changeset 30085:6cf446a6553b

vasnprintf-posix: handle large precision via %.*d * lib/vasnprintf.c (VASNPRINTF): Don't pass precision to snprintf when handling it ourselves. * tests/test-vasnprintf-posix.c (test_function): Add test. * tests/test-snprintf-posix.h (test_function): Likewise. * tests/test-sprintf-posix.h (test_function): Likewise. * tests/test-vasprintf-posix.c (test_function): Likewise. Reported by Alain Guibert. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Mon, 01 Sep 2008 21:28:44 -0600
parents 392701397617
children 1a9105f2aabf
files ChangeLog lib/vasnprintf.c tests/test-snprintf-posix.h tests/test-sprintf-posix.h tests/test-vasnprintf-posix.c tests/test-vasprintf-posix.c
diffstat 6 files changed, 62 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Sep 01 19:59:38 2008 -0600
+++ b/ChangeLog	Mon Sep 01 21:28:44 2008 -0600
@@ -1,3 +1,14 @@
+2008-09-02  Eric Blake  <ebb9@byu.net>
+
+	vasnprintf-posix: handle large precision via %.*d
+	* lib/vasnprintf.c (VASNPRINTF): Don't pass precision to snprintf
+	when handling it ourselves.
+	* tests/test-vasnprintf-posix.c (test_function): Add test.
+	* tests/test-snprintf-posix.h (test_function): Likewise.
+	* tests/test-sprintf-posix.h (test_function): Likewise.
+	* tests/test-vasprintf-posix.c (test_function): Likewise.
+	Reported by Alain Guibert.
+
 2008-09-01  Eric Blake  <ebb9@byu.net>
 
 	c-stack: make configure-time check more robust
--- a/lib/vasnprintf.c	Mon Sep 01 19:59:38 2008 -0600
+++ b/lib/vasnprintf.c	Mon Sep 01 21:28:44 2008 -0600
@@ -4176,7 +4176,7 @@
 		      abort ();
 		    prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int;
 		  }
-		if (dp->precision_arg_index != ARG_NONE)
+		if (!prec_ourselves && dp->precision_arg_index != ARG_NONE)
 		  {
 		    if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
 		      abort ();
--- a/tests/test-snprintf-posix.h	Mon Sep 01 19:59:38 2008 -0600
+++ b/tests/test-snprintf-posix.h	Mon Sep 01 21:28:44 2008 -0600
@@ -2950,6 +2950,18 @@
   {
     char result[5000];
     int retval =
+      my_snprintf (result, sizeof (result), "%.*d %d", 4000, 1234567, 99);
+    size_t i;
+    ASSERT (result != NULL);
+    for (i = 0; i < 4000 - 7; i++)
+      ASSERT (result[i] == '0');
+    ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  {
+    char result[5000];
+    int retval =
       my_snprintf (result, sizeof (result), "%.4000d %d", -1234567, 99);
     size_t i;
     ASSERT (result != NULL);
--- a/tests/test-sprintf-posix.h	Mon Sep 01 19:59:38 2008 -0600
+++ b/tests/test-sprintf-posix.h	Mon Sep 01 21:28:44 2008 -0600
@@ -2924,6 +2924,18 @@
   {
     char result[5000];
     int retval =
+      my_sprintf (result, "%.*d %d", 4000, 1234567, 99);
+    size_t i;
+    ASSERT (result != NULL);
+    for (i = 0; i < 4000 - 7; i++)
+      ASSERT (result[i] == '0');
+    ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  {
+    char result[5000];
+    int retval =
       my_sprintf (result, "%.4000d %d", -1234567, 99);
     size_t i;
     ASSERT (result != NULL);
--- a/tests/test-vasnprintf-posix.c	Mon Sep 01 19:59:38 2008 -0600
+++ b/tests/test-vasnprintf-posix.c	Mon Sep 01 21:28:44 2008 -0600
@@ -3457,6 +3457,19 @@
   {
     size_t length;
     char *result =
+      my_asnprintf (NULL, &length, "%.*d %d", 4000, 1234567, 99);
+    size_t i;
+    ASSERT (result != NULL);
+    for (i = 0; i < 4000 - 7; i++)
+      ASSERT (result[i] == '0');
+    ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  {
+    size_t length;
+    char *result =
       my_asnprintf (NULL, &length, "%.4000d %d", -1234567, 99);
     size_t i;
     ASSERT (result != NULL);
--- a/tests/test-vasprintf-posix.c	Mon Sep 01 19:59:38 2008 -0600
+++ b/tests/test-vasprintf-posix.c	Mon Sep 01 21:28:44 2008 -0600
@@ -3438,6 +3438,19 @@
   {
     char *result;
     int retval =
+      my_asprintf (&result, "%.*d %d", 4000, 1234567, 99);
+    size_t i;
+    ASSERT (result != NULL);
+    for (i = 0; i < 4000 - 7; i++)
+      ASSERT (result[i] == '0');
+    ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+
+  {
+    char *result;
+    int retval =
       my_asprintf (&result, "%.4000d %d", -1234567, 99);
     size_t i;
     ASSERT (result != NULL);