bug-m4
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: diversion failure [was: snapshot in preparation for m4 1.4.12]


From: Eric Blake
Subject: Re: diversion failure [was: snapshot in preparation for m4 1.4.12]
Date: Mon, 01 Sep 2008 21:30:06 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080708 Thunderbird/2.0.0.16 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 8/19/2008 6:29 AM:
> According to Alain Guibert on 8/19/2008 4:40 AM:
>> Sure. There is a segfault on the test for large precisions, on
>> "%.4000d". On libc5 this format works well until "%.1020d", but
>> segfaults for "%.1021d" and above.
> 
> Bruno, this looks like a vasnprintf bug, since configure accurately
> determined that:
> 
>> | checking whether printf supports large precisions... no
> 
> I'm not sure where to look in vasnprintf to try fixing this, although it
> seems like it might be as simple as using NEED_PRINTF_UNBOUNDED_PRECISION
> in more places.  Do you have suggestions?

In looking at this further, it looks like line 4179 of vasnprintf.c should
_not_ count precision as a prefix if prec_ourselves is nonzero.  Without
the patch to vasnprintf.c, the added test in test-vasnprintf-posix dumped
core when I used

$ gl_cv_func_printf_sizes_c99=no gl_cv_func_printf_infinite=no
gl_cv_func_printf_directive_a=no gl_cv_func_printf_directive_f=no
gl_cv_func_printf_flag_zero=no gl_cv_func_printf_precision=no
./gnulib-tool --with-tests --test vasnprintf-posix

on cygwin.  I traced this to an attempt to call snprintf(buf, 12, "%d%n",
4000, 1234567, &count).

OK to apply?  Are there other files in lib or tests that need matching
modifications?

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAki8sz4ACgkQ84KuGfSFAYDjMQCcDjbmnyHYkR65Tl/HJjW+T62x
p6oAnixEzpUY4fvE12JQGA8Qg1PQKsnB
=7XSu
-----END PGP SIGNATURE-----
>From e9d8a313d2d20e4286dea8302373837ad1b2d95a Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Mon, 1 Sep 2008 21:28:44 -0600
Subject: [PATCH] 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.
Reported by Alain Guibert.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog                     |    6 ++++++
 lib/vasnprintf.c              |    2 +-
 tests/test-vasnprintf-posix.c |   13 +++++++++++++
 3 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0277d1c..84c8ed6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2008-09-01  Eric Blake  <address@hidden>
 
+       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.
+       Reported by Alain Guibert.
+
        c-stack: make configure-time check more robust
        * m4/c-stack.m4 (AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC): Check for
        successful sigaction call.
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 89829c9..4ddf45f 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -4176,7 +4176,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                      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 ();
diff --git a/tests/test-vasnprintf-posix.c b/tests/test-vasnprintf-posix.c
index 42d9267..4c9d47e 100644
--- a/tests/test-vasnprintf-posix.c
+++ b/tests/test-vasnprintf-posix.c
@@ -3457,6 +3457,19 @@ test_function (char * (*my_asnprintf) (char *, size_t *, 
const char *, ...))
   {
     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);
-- 
1.6.0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]