[PATCH v6 1/3] Add [v]aprintf(3)

Andreas Schwab schwab@suse.de
Wed May 20 13:59:58 GMT 2026


On Mai 18 2026, Alejandro Colomar wrote:

> diff --git a/libio/tst-aprintf.c b/libio/tst-aprintf.c
> new file mode 100644
> index 00000000..e10eb591
> --- /dev/null
> +++ b/libio/tst-aprintf.c
> @@ -0,0 +1,57 @@
> +/* Test aprintf.
> +   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 <errno.h>
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include <support/check.h>
> +#include <sys/resource.h>
> +
> +static int
> +do_test (void)
> +{
> +  char *buf;
> +
> +  /* Success */
> +  buf = aprintf ("foo %d", 42);
> +  TEST_COMPARE_STRING (buf, "foo 42");
> +  free(buf);
> +
> +  {
> +    /* Avoid -Wformat-overflow warning.  */
> +    const char *volatile format = "%2000000000d %2000000000d";

This can be accomplished by temporarily disabling that option.

-- 
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