]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
2007-01-22 Ulrich Drepper <drepper@redhat.com>
authorJakub Jelinek <jakub@redhat.com>
Thu, 12 Jul 2007 14:45:55 +0000 (14:45 +0000)
committerJakub Jelinek <jakub@redhat.com>
Thu, 12 Jul 2007 14:45:55 +0000 (14:45 +0000)
[BZ #3902]
* stdio-common/_itoa.c (_itoa): Make sure at least a zero is emitted.
* stdio-common/Makefile (tests): Add bug17.
* stdio-common/bug17.c: New file.

ChangeLog
stdio-common/Makefile
stdio-common/_itoa.c
stdio-common/bug17.c [new file with mode: 0644]

index 2adaaf9f8da75244a3c9ee3173ff88166d299d17..eb8f568b2979ebcbb520ffaa5def37f39a9633ec 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-01-22  Ulrich Drepper  <drepper@redhat.com>
+
+       [BZ #3902]
+       * stdio-common/_itoa.c (_itoa): Make sure at least a zero is emitted.
+       * stdio-common/Makefile (tests): Add bug17.
+       * stdio-common/bug17.c: New file.
+
 2007-01-15  Jakub Jelinek  <jakub@redhat.com>
 
        * soft-fp/op-common.h (FP_TRUNC): When truncating a NaN, clear
index 37bcdb3bc844868278cc40f1097f19164ebf5764..71e37b9ade9153bcc9925add118c98ac3ade74f9 100644 (file)
@@ -54,7 +54,7 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \
         tst-swprintf tst-fseek tst-fmemopen test-vfprintf tst-gets \
         tst-perror tst-sprintf tst-rndseek tst-fdopen tst-fphex bug14 bug15 \
         tst-popen tst-unlockedio tst-fmemopen2 tst-put-error tst-fgets \
-        tst-fwrite bug16
+        tst-fwrite bug16 bug17
 
 test-srcs = tst-unbputc tst-printf
 
index f61b23fceb3e25378c56b63fb898e6cab1874e66..d018313213ab4bba2fdcbbbb00b7050d891b9a3e 100644 (file)
@@ -269,6 +269,7 @@ _itoa (value, buflim, base, upper_case)
 
     default:
       {
+       char *bufend = buflim;
 #if BITS_PER_MP_LIMB == 64
        mp_limb_t base_multiplier = brec->base_multiplier;
        if (brec->flag)
@@ -454,6 +455,8 @@ _itoa (value, buflim, base, upper_case)
          }
        while (n != 0);
 #endif
+       if (buflim == bufend)
+         *--buflim = '0';
       }
       break;
     }
diff --git a/stdio-common/bug17.c b/stdio-common/bug17.c
new file mode 100644 (file)
index 0000000..2ef3986
--- /dev/null
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <string.h>
+
+static int
+do_test (void)
+{
+  static const char expect[] = "0, 0, 0";
+  char buf[100];
+  int status = 0;
+
+  static const char fmt1[] = "%0d, %0ld, %0lld";
+  snprintf (buf, sizeof (buf), fmt1, 0, 0L, 0LL);
+  if (strcmp (buf, expect) != 0)
+    {
+      printf ("\"%s\": got \"%s\", expected \"%s\"\n", fmt1, buf, expect);
+      status = 1;
+    }
+
+  static const char fmt2[] = "%0u, %0lu, %0llu";
+  snprintf (buf, sizeof (buf), fmt2, 0u, 0uL, 0uLL);
+  if (strcmp (buf, expect) != 0)
+    {
+      printf ("\"%s\": got \"%s\", expected \"%s\"\n", fmt2, buf, expect);
+      status = 1;
+    }
+
+  return status;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"