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

Alejandro Colomar alx@kernel.org
Wed May 27 19:28:17 GMT 2026


Hi Andreas,

On 2026-05-21T11:27:29+0200, Alejandro Colomar wrote:
> Hi Andreas,
> 
> On 2026-05-21T10:21:18+0200, Andreas Schwab wrote:
> > On Mai 20 2026, Alejandro Colomar wrote:
> > 
> > > 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.
> > 
> > Either of those would be ok with me.
> 
> Thanks!  I prefer C, so I'll do that.

In the end, I've done D.  The reason is that this test should actually
be different.  We shouldn't expect a failure here; the only reason it
fails is that the current implementation is less-than-ideal.  A future
better implementation should remove the EOVERFLOW error.

Thus, I've changed this test to not expect EOVERFLOW, but rather expect
a non-null pointer (success).

	diff --git i/libio/tst-aprintf.c w/libio/tst-aprintf.c
	index e10eb591490c..d0f96c72b81b 100644
	--- i/libio/tst-aprintf.c
	+++ w/libio/tst-aprintf.c
	@@ -33,13 +33,21 @@ do_test (void)
	   free(buf);
	 
	   {
	-    /* Avoid -Wformat-overflow warning.  */
	-    const char *volatile format = "%2000000000d %2000000000d";
	-    buf = aprintf (format, 1, 2);
	-    TEST_VERIFY (buf == NULL);
	+    /* -Wformat-overflow warns that the format would produce more than
	+       INT_MAX bytes; however, this function does not share this
	+       inherent limitation of other printf-like functions.  The current
	+       implementation fails with EOVERFLOW, because it's a trivial
	+       wrapper; however, in the future we should improve the function so
	+       that this doesn't fail anymore with EOVERFLOW.  When that is
	+       implemented, this test will stop failing.  */
	+    DIAG_PUSH_NEEDS_COMMENT;
	+    DIAG_IGNORE_NEEDS_COMMENT (8, "-Wformat-overflow=");
	+    buf = aprintf ("%2000000000d %2000000000d", 1, 2);
	+    DIAG_POP_NEEDS_COMMENT;
	+    TEST_VERIFY (buf != NULL);
	   }
	   if (errno != ENOMEM)
	-    TEST_COMPARE (errno, EOVERFLOW);
	+    TEST_COMPARE (errno, 0);
	 
	   /* Force ENOMEM in the test below.  */
	   struct rlimit rl;

I've based the use of DIAG_ on what I've found in existing code:

	$ grep -rn DIAG_IGNORE_NEEDS_COMMENT.*format-overflow
	resolv/res_debug.c:1087:	DIAG_IGNORE_NEEDS_COMMENT (8, "-Wformat-overflow=");
	sunrpc/netname.c:57:  DIAG_IGNORE_NEEDS_COMMENT (8, "-Wformat-overflow");
	stdio-common/bug22.c:38:  DIAG_IGNORE_NEEDS_COMMENT (9, "-Wformat-overflow=");
	stdio-common/bug22.c:50:  DIAG_IGNORE_NEEDS_COMMENT (9, "-Wformat-overflow=");
	stdio-common/bug22.c:67:  DIAG_IGNORE_NEEDS_COMMENT (9, "-Wformat-overflow=");
	stdio-common/tst-printf.c:117:  DIAG_IGNORE_NEEDS_COMMENT (9, "-Wformat-overflow=");

Although there seems to be discrepancy in the GCC versions.  I've used
the most conservative number.

One concern is that this test might still fail with ENOMEM.  Does the
above diff seem good to you?  I haven't tested it yet; I'll start the
testsuite now.


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/20260527/34990f72/attachment-0001.sig>


More information about the Libc-alpha mailing list