diff options
| author | Joseph Myers <josmyers@redhat.com> | 2025-01-28 19:38:27 +0000 |
|---|---|---|
| committer | Joseph Myers <josmyers@redhat.com> | 2025-01-28 19:38:27 +0000 |
| commit | 377e9733b50ce41e496c467ddcc112f73c88f3bd (patch) | |
| tree | 2aaeddae812df4ad17ff3ca426b59c18cd307096 /libio | |
| parent | 1515f74fd81035a79861cd9fa12053fa9450ec65 (diff) | |
| download | glibc-377e9733b50ce41e496c467ddcc112f73c88f3bd.tar.xz glibc-377e9733b50ce41e496c467ddcc112f73c88f3bd.zip | |
Fix fflush after ungetc on input file (bug 5994)
As discussed in bug 5994 (plus duplicates), POSIX requires fflush
after ungetc to discard pushed-back characters but preserve the file
position indicator. For this purpose, each ungetc decrements the file
position indicator by 1; it is unspecified after ungetc at the start
of the file, and after ungetwc, so no special handling is needed for
either of those cases.
This is fixed with appropriate logic in _IO_new_file_sync. I haven't
made any attempt to test or change things in this area for the "old"
functions; the case of files using mmap is addressed in a subsequent
patch (and there seem to be no problems in this area with files opened
with fmemopen).
Tested for x86_64.
Diffstat (limited to 'libio')
| -rw-r--r-- | libio/fileops.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/libio/fileops.c b/libio/fileops.c index 12b440b09d..42e695265d 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -800,6 +800,11 @@ _IO_new_file_sync (FILE *fp) if (fp->_IO_write_ptr > fp->_IO_write_base) if (_IO_do_flush(fp)) return EOF; delta = fp->_IO_read_ptr - fp->_IO_read_end; + if (_IO_in_backup (fp)) + { + _IO_switch_to_main_get_area (fp); + delta += fp->_IO_read_ptr - fp->_IO_read_end; + } if (delta != 0) { off64_t new_pos = _IO_SYSSEEK (fp, delta, 1); |
