mirror of
git://git.musl-libc.org/musl
synced 2024-12-17 12:14:42 +00:00
fmemopen fixes
disallow seek past end of buffer (per posix) fix position accounting to include data buffered for read don't set eof flag when no data was requested
This commit is contained in:
parent
7ee3dcb3c6
commit
f81279ff58
@ -16,7 +16,7 @@ fail:
|
||||
return -1;
|
||||
}
|
||||
base = (size_t [3]){0, c->pos, c->len}[whence];
|
||||
if (off < -base || off > SSIZE_MAX-base) goto fail;
|
||||
if (off < -base || off > (ssize_t)c->size-base) goto fail;
|
||||
return c->pos = base+off;
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ static size_t mread(FILE *f, unsigned char *buf, size_t len)
|
||||
{
|
||||
struct cookie *c = f->cookie;
|
||||
size_t rem = c->size - c->pos;
|
||||
if (!len) return 0;
|
||||
if (len > rem) len = rem;
|
||||
memcpy(buf, c->buf+c->pos, len);
|
||||
c->pos += len;
|
||||
@ -32,6 +33,7 @@ static size_t mread(FILE *f, unsigned char *buf, size_t len)
|
||||
f->rpos = f->buf;
|
||||
f->rend = f->buf + rem;
|
||||
memcpy(f->rpos, c->buf+c->pos, rem);
|
||||
c->pos += rem;
|
||||
if (!len) f->flags |= F_EOF;
|
||||
return len;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user