]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
2007-05-21 Jakub Jelinek <jakub@redhat.com>
authorJakub Jelinek <jakub@redhat.com>
Thu, 12 Jul 2007 15:23:38 +0000 (15:23 +0000)
committerJakub Jelinek <jakub@redhat.com>
Thu, 12 Jul 2007 15:23:38 +0000 (15:23 +0000)
[BZ #4514]
* stdio-common/vfprintf.c (vfprintf): Don't shadow workstart variable,
reinitialize workend at the start of each do_positional format spec
loop, free workstart before do_positional loops.
(printf_unknown): Fix size of work_buffer.
* stdio-common/tst-sprintf.c (main): Add 3 new testcases.

ChangeLog
stdio-common/tst-sprintf.c
stdio-common/vfprintf.c

index a54da6b92fe1c485a7ee07dd24c10e7552dec7c8..a9f72390a21cf9ba8ea51040164b2442232b3137 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-05-21  Jakub Jelinek  <jakub@redhat.com>
+
+       [BZ #4514]
+       * stdio-common/vfprintf.c (vfprintf): Don't shadow workstart variable,
+       reinitialize workend at the start of each do_positional format spec
+       loop, free workstart before do_positional loops.
+       (printf_unknown): Fix size of work_buffer.
+       * stdio-common/tst-sprintf.c (main): Add 3 new testcases.
+
 2007-05-10  Ulrich Drepper  <drepper@redhat.com>
 
        * include/sys/cdefs.h: Redefine __nonnull so that test for
index c61d3b50e4f78baf32fc787bafefc49a05e6677a..c04fef18f4b14cc22943a71985e00fcbb45e22fb 100644 (file)
@@ -37,5 +37,26 @@ main (void)
       free (dst);
     }
 
+  if (sprintf (buf, "%1$d%3$.*2$s%4$d", 7, 67108863, "x", 8) != 3
+      || strcmp (buf, "7x8") != 0)
+    {
+      printf ("sprintf (buf, \"%%1$d%%3$.*2$s%%4$d\", 7, 67108863, \"x\", 8) produced `%s' output", buf);
+      result = 1;
+    }
+
+  if (sprintf (buf, "%67108863.16\"%d", 7) != 14
+      || strcmp (buf, "%67108863.16\"7") != 0)
+    {
+      printf ("sprintf (buf, \"%%67108863.16\\\"%%d\", 7) produced `%s' output", buf);
+      result = 1;
+    }
+
+  if (sprintf (buf, "%*\"%d", 0x3ffffff, 7) != 11
+      || strcmp (buf, "%67108863\"7") != 0)
+    {
+      printf ("sprintf (buf, \"%%*\\\"%%d\", 0x3ffffff, 7) produced `%s' output", buf);
+      result = 1;
+    }
+
   return result;
 }
index 1377e3c17edc31d25822a731f1503c5733634af9..9c9e9a5d9d75ccb73647196bef13c8a1f02528f4 100644 (file)
@@ -1626,6 +1626,8 @@ do_positional:
     /* Just a counter.  */
     size_t cnt;
 
+    free (workstart);
+    workstart = NULL;
 
     if (grouping == (const char *) -1)
       {
@@ -1800,7 +1802,9 @@ do_positional:
        int use_outdigits = specs[nspecs_done].info.i18n;
        char pad = specs[nspecs_done].info.pad;
        CHAR_T spec = specs[nspecs_done].info.spec;
-       CHAR_T *workstart = NULL;
+
+       workstart = NULL;
+       workend = &work_buffer[sizeof (work_buffer) / sizeof (CHAR_T)];
 
        /* Fill in last information.  */
        if (specs[nspecs_done].width_arg != -1)
@@ -1896,8 +1900,7 @@ do_positional:
            break;
          }
 
-       if (__builtin_expect (workstart != NULL, 0))
-         free (workstart);
+       free (workstart);
        workstart = NULL;
 
        /* Write the following constant string.  */
@@ -1925,7 +1928,7 @@ printf_unknown (FILE *s, const struct printf_info *info,
 
 {
   int done = 0;
-  CHAR_T work_buffer[MAX (info->width, info->spec) + 32];
+  CHAR_T work_buffer[MAX (sizeof (info->width), sizeof (info->prec)) * 3];
   CHAR_T *const workend
     = &work_buffer[sizeof (work_buffer) / sizeof (CHAR_T)];
   register CHAR_T *w;