[PATCH v4 0/2] libio: Keep memstream result buffers independent of setvbuf

Gao Xiang gaoxiang@kylinos.cn
Thu May 7 09:39:58 GMT 2026


From: Xiang Gao <gaoxiang@kylinos.cn>

This series fixes two paths where setbuf/setvbuf can interfere with 
the growable result buffers managed by open_memstream and
open_wmemstream.

Patch 1 keeps the v2 setbuf fix: memstream-specific setbuf hooks keep
the internal growable result buffer unchanged.

Patch 2 handles the setvbuf (stream, NULL, _IOFBF, 0) path, which can
call _IO_DOALLOCATE and return without invoking the stream setbuf hook. 

Changes in v4:
 * Refactor the test cases in both patches by using libio/tst-memstream.h,
   so that the regression tests cover both open_memstream and
   open_wmemstream, as suggested by Andreas Schwab.
 * Use TEST_VERIFY_EXIT for pointer guard checks.
 * Fix typos.

Tested on x86_64-linux-gnu with no regression:
  make -j$(nproc) subdirs=libio check


Xiang Gao (2):
  libio: Ignore setbuf for open_memstream and open_wmemstream [BZ
    #34019]
  libio: Ignore doallocate for open_memstream and open_wmemstream [BZ
    #34019]

 libio/Makefile                            |  4 ++
 libio/libioP.h                            | 15 ++++--
 libio/memstream.c                         | 20 ++++++++
 libio/tst-memstream-setbuf.c              | 41 +++++++++++++++
 libio/tst-memstream-setvbuf-doallocate.c  | 61 +++++++++++++++++++++++
 libio/tst-wmemstream-setbuf.c             | 20 ++++++++
 libio/tst-wmemstream-setvbuf-doallocate.c | 20 ++++++++
 libio/vtables.c                           | 12 +++--
 libio/wmemstream.c                        | 20 ++++++++
 9 files changed, 205 insertions(+), 8 deletions(-)
 create mode 100644 libio/tst-memstream-setbuf.c
 create mode 100644 libio/tst-memstream-setvbuf-doallocate.c
 create mode 100644 libio/tst-wmemstream-setbuf.c
 create mode 100644 libio/tst-wmemstream-setvbuf-doallocate.c

-- 
2.53.0



More information about the Libc-alpha mailing list