diff options
author | Roland McGrath <roland@gnu.org> | 2005-02-16 09:45:11 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 2005-02-16 09:45:11 +0000 |
commit | b25db04c7b8c439edc5fb898356c80645cf17419 (patch) | |
tree | 2b0e2b29e9e962fbc332561dc0283b322c785b74 /libio | |
parent | d571e9eeea9deb191db1660635867cc33ac5917f (diff) |
2005-01-05 Ulrich Drepper <drepper@redhat.com>
[BZ #730]
* libio/iofopncook.c (_IO_cookie_seekoff): Define. Mark offset as
invalid to disable optimizations in fileops which won't work here.
(_IO_cookie_jumps): Use it.
(_IO_old_cookie_jumps): Likewise.
* libio/fmemopen.c (fmemopen_seek): Result must be returned in *P,
not the return value.
* stdio-common/Makefile (tests): Add tst-fmemopen2.
* stdio-common/tst-fmemopen2.c: New file.
Diffstat (limited to 'libio')
-rw-r--r-- | libio/fmemopen.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/libio/fmemopen.c b/libio/fmemopen.c index ab6ffdd678..c22cba1ec4 100644 --- a/libio/fmemopen.c +++ b/libio/fmemopen.c @@ -27,8 +27,6 @@ * but couldn't find it in libio. The following snippet of code is an * attempt to implement what glibc's documentation describes. * - * No, it isn't really tested yet. :-) - * * * * I already see some potential problems: @@ -166,7 +164,7 @@ fmemopen_seek (void *cookie, _IO_off64_t *p, int w) break; case SEEK_END: - np = c->size - *p; + np = c->maxpos - *p; break; default: @@ -176,9 +174,9 @@ fmemopen_seek (void *cookie, _IO_off64_t *p, int w) if (np < 0 || (size_t) np > c->size) return -1; - c->pos = np; + *p = c->pos = np; - return np; + return 0; } @@ -203,6 +201,13 @@ fmemopen (void *buf, size_t len, const char *mode) cookie_io_functions_t iof; fmemopen_cookie_t *c; + if (len == 0) + { + einval: + __set_errno (EINVAL); + return NULL; + } + c = (fmemopen_cookie_t *) malloc (sizeof (fmemopen_cookie_t)); if (c == NULL) return NULL; @@ -220,7 +225,12 @@ fmemopen (void *buf, size_t len, const char *mode) c->buffer[0] = '\0'; } else - c->buffer = buf; + { + if ((uintptr_t) len > -(uintptr_t) buf) + goto einval; + + c->buffer = buf; + } c->size = len; |