mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-24 14:00:30 +00:00
645f97ced4
This patches fixes multiples issues on open_{w}memstream reported on both BZ#18241 and BZ#20181: - failed fseek does not set errno. - negative offset in fseek fails even when resulting position is a valid one. - a flush after write if the current write position is not at the end of the stream currupt data. The main fix is on seek operation for memstream (_IO_{w}str_seekoff), where both _IO_read_ptr and _IO_read_end pointer are updated if a write operation has occured (similar to default file operations). Also, to calculate the offset on both read and write pointers, a temporary value is instead of updating the argument supplied value. Negative offset are valid if resulting internal pointer is within the range of _IO_{read,write}_base and _IO_{read,write}_end. Also POSIX states that a null or wide null shall be appended to the current buffer iff a write moves the position to a value larger than the current lenght. Current implementation appends a null or wide null regardless of this condition. This patch fixes it by removing the 'else' condition on _IO_{w}mem_sync. Checked on x86_64. [BZ #18241] [BZ #20181] * libio/Makefile (test): Add tst-memstream3 and tst-wmemstream3. * libio/memstream.c (_IO_mem_sync): Only append a null byte if write position is at the end the buffer. * libio/wmemstream.c (_IO_wmem_sync): Likewise. * libio/strops.c (_IO_str_switch_to_get_mode): New function. (_IO_str_seekoff): Set correct offset from negative displacement and set EINVAL for invalid ones. * libio/wstrops.c (enlarge_userbuf): Use correct function to calculate buffer length. (_IO_wstr_switch_to_get_mode): New function. (_IO_wstr_seekoff): Set correct offset from negative displacement and set EINVAL for invalid ones. * libio/tst-memstream3.c: New file. * libio/tst-wmemstream3.c: Likewise. * manual/examples/memstrm.c: Remove warning when priting size_t. |
||
---|---|---|
.. | ||
add.c | ||
argp-ex1.c | ||
argp-ex2.c | ||
argp-ex3.c | ||
argp-ex4.c | ||
atexit.c | ||
db.c | ||
dir2.c | ||
dir.c | ||
execinfo.c | ||
filecli.c | ||
filesrv.c | ||
fmtmsgexpl.c | ||
genpass.c | ||
inetcli.c | ||
inetsrv.c | ||
isockad.c | ||
longopt.c | ||
memopen.c | ||
memstrm.c | ||
mkdirent.c | ||
mkfsock.c | ||
mkisock.c | ||
mygetpass.c | ||
ofdlocks.c | ||
pipe.c | ||
popen.c | ||
README | ||
rprintf.c | ||
search.c | ||
select.c | ||
setjmp.c | ||
sigh1.c | ||
sigusr.c | ||
stpcpy.c | ||
strdupa.c | ||
strftim.c | ||
subopt.c | ||
swapcontext.c | ||
termios.c | ||
testopt.c | ||
testpass.c | ||
timeval_subtract.c |
These are source files for example code that appears in The GNU C Library Reference Manual. While the manual itself is licensed under the terms of the GNU Free Documentation License, you can use these source files on their own under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License, or (at your option) any later version.