[PATCH v6 1/3] Add [v]aprintf(3)
Alejandro Colomar
alx@kernel.org
Wed May 20 14:43:40 GMT 2026
Hi Andreas,
On 2026-05-20T15:59:58+0200, Andreas Schwab wrote:
> 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.
Thanks! I copied this from the asprintf(3) tests. Which of the
following do you prefer?
A) Follow what's done in asprintf(3) tests.
B) Follow what's done in asprintf(3) tests, and later improve this for
both tests with your suggestion.
C) First improve the asprintf(3) tests with your suggestion, and then
add this test cleanly.
D) Follow your suggestion here, and keep the asprintf(3) tests
untouched.
Have a lovely day!
Alex
--
<https://www.alejandro-colomar.es>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20260520/25724390/attachment.sig>
More information about the Libc-alpha
mailing list