bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Subject: Re: printf with %n directives
Date: Fri, 23 Feb 2024 13:09:49 +0100	[thread overview]
Message-ID: <7672049.31r3eYUQgx@nimes> (raw)
In-Reply-To: <4169477.h4nFI6E9mP@nimes>

> 2024-02-21  Bruno Haible  <bruno@clisp.org>
> 
> 	*printf-posix: Disable support for the 'n' directive by default.

This produces 24 test failures in libunistring. Fixed as follows:


2024-02-23  Bruno Haible  <bruno@clisp.org>

	unistdio/*printf tests: Update expected test results regarding %n.
	* tests/unistdio/test-u8-printf1.h (test_xfunction): If
	NEED_PRINTF_WITH_N_DIRECTIVE is not defined, expect a NULL result in the
	%n test.
	* tests/unistdio/test-u16-printf1.h (test_xfunction): Likewise.
	* tests/unistdio/test-u32-printf1.h (test_xfunction): Likewise.
	* tests/unistdio/test-ulc-printf1.h (test_xfunction): Likewise.

diff --git a/tests/unistdio/test-u16-printf1.h b/tests/unistdio/test-u16-printf1.h
index 72655e7202..e501c9e462 100644
--- a/tests/unistdio/test-u16-printf1.h
+++ b/tests/unistdio/test-u16-printf1.h
@@ -1032,12 +1032,16 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...))
     int count = -1;
     uint16_t *result =
       my_xasprintf ("%d %n", 123, &count, 33, 44, 55);
+#if NEED_PRINTF_WITH_N_DIRECTIVE
     static const uint16_t expected[] =
       { '1', '2', '3', ' ', 0 };
     ASSERT (result != NULL);
     ASSERT (u16_strcmp (result, expected) == 0);
     ASSERT (count == 4);
     free (result);
+#else
+    ASSERT (result == NULL);
+#endif
   }
 
   /* Test the support of the POSIX/XSI format strings with positions.  */
diff --git a/tests/unistdio/test-u32-printf1.h b/tests/unistdio/test-u32-printf1.h
index 0cebba2819..ae0edc6a63 100644
--- a/tests/unistdio/test-u32-printf1.h
+++ b/tests/unistdio/test-u32-printf1.h
@@ -1032,12 +1032,16 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...))
     int count = -1;
     uint32_t *result =
       my_xasprintf ("%d %n", 123, &count, 33, 44, 55);
+#if NEED_PRINTF_WITH_N_DIRECTIVE
     static const uint32_t expected[] =
       { '1', '2', '3', ' ', 0 };
     ASSERT (result != NULL);
     ASSERT (u32_strcmp (result, expected) == 0);
     ASSERT (count == 4);
     free (result);
+#else
+    ASSERT (result == NULL);
+#endif
   }
 
   /* Test the support of the POSIX/XSI format strings with positions.  */
diff --git a/tests/unistdio/test-u8-printf1.h b/tests/unistdio/test-u8-printf1.h
index 2b762737f1..3e8999b638 100644
--- a/tests/unistdio/test-u8-printf1.h
+++ b/tests/unistdio/test-u8-printf1.h
@@ -786,11 +786,15 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
     int count = -1;
     uint8_t *result =
       my_xasprintf ("%d %n", 123, &count, 33, 44, 55);
+#if NEED_PRINTF_WITH_N_DIRECTIVE
     static const uint8_t expected[] = "123 ";
     ASSERT (result != NULL);
     ASSERT (u8_strcmp (result, expected) == 0);
     ASSERT (count == 4);
     free (result);
+#else
+    ASSERT (result == NULL);
+#endif
   }
 
   /* Test the support of the POSIX/XSI format strings with positions.  */
diff --git a/tests/unistdio/test-ulc-printf1.h b/tests/unistdio/test-ulc-printf1.h
index 7617185a08..49089c1bfd 100644
--- a/tests/unistdio/test-ulc-printf1.h
+++ b/tests/unistdio/test-ulc-printf1.h
@@ -670,10 +670,14 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...))
     int count = -1;
     char *result =
       my_xasprintf ("%d %n", 123, &count, 33, 44, 55);
+#if NEED_PRINTF_WITH_N_DIRECTIVE
     ASSERT (result != NULL);
     ASSERT (strcmp (result, "123 ") == 0);
     ASSERT (count == 4);
     free (result);
+#else
+    ASSERT (result == NULL);
+#endif
   }
 
   /* Test the support of the POSIX/XSI format strings with positions.  */





      reply	other threads:[~2024-02-23 12:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-20 15:46 printf with %n directives Bruno Haible
2024-02-21 14:54 ` Bruno Haible
2024-02-23 12:09   ` Bruno Haible [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7672049.31r3eYUQgx@nimes \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).