Skip to content

Commit 3dae86e

Browse files
committed
fmemopen: allow seeking beyond the end of current data length
As long as we remain within the allocated buffer size this is fine. Fixes test09 in the NetBSD fmemopen tests.
1 parent 2808c0f commit 3dae86e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

newlib/libc/tinystdio/fmemopen.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ __fmem_seek(FILE *f, off_t pos, int whence)
110110
pos += mf->size;
111111
break;
112112
}
113-
if (pos < 0 || mf->size < (size_t)pos)
113+
_Static_assert(sizeof(off_t) >= sizeof(size_t), "must avoid truncation");
114+
if (pos < 0 || (off_t)mf->bufsize < pos)
114115
return EOF;
115116
mf->pos = pos;
116117
return pos;

0 commit comments

Comments
 (0)