[PATCH v3 2/2] libio: Ignore doallocate for open_memstream and open_wmemstream [BZ #34019]

Andreas Schwab schwab@suse.de
Wed May 6 10:38:28 GMT 2026


On Mai 06 2026, Gao Xiang wrote:

> diff --git a/libio/tst-wmemstream-setvbuf-doallocate.c b/libio/tst-wmemstream-setvbuf-doallocate.c
> new file mode 100644
> index 0000000000..595a716db5
> --- /dev/null
> +++ b/libio/tst-wmemstream-setvbuf-doallocate.c
> @@ -0,0 +1,64 @@
> +/* Test setvbuf on open_wmenstream, BZ #34019.
> +   Copyright (C) 2026 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <wchar.h>
> +#include <support/check.h>
> +
> +static int
> +do_test (void)
> +{
> +  /* Regression test for setvbuf doallocate on open_wmemstream.
> +     This test cover the _IO_setvbuf path for:
> +
> +     setvbuf (stream, NULL, _IOFBF, 0)
> +
> +     This path may call _IO_DOALLOCATE and return without invoking
> +     the stream setbuf hook. For open_wmemstream, the generic wide
> +     doallocate hook must not replace the growable  result buffer.  */
> +
> +  wchar_t *wbuf = NULL;
> +  size_t wlen = 0;
> +  FILE *fp = open_wmemstream (&wbuf, &wlen);

If you base the test on libio/tst-memstream.h you can test both narrow
and wide streams with the same test.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


More information about the Libc-alpha mailing list