From: Jakub Jelinek Date: Thu, 12 Jul 2007 14:45:55 +0000 (+0000) Subject: 2007-01-22 Ulrich Drepper X-Git-Tag: cvs/fedora-glibc-2_5-20070712T1701~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45138560bb92eb77179638ab063917cf5c6026c7;p=thirdparty%2Fglibc.git 2007-01-22 Ulrich Drepper [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. --- diff --git a/ChangeLog b/ChangeLog index 2adaaf9f8da..eb8f568b297 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-01-22 Ulrich Drepper + + [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 * soft-fp/op-common.h (FP_TRUNC): When truncating a NaN, clear diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 37bcdb3bc84..71e37b9ade9 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -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 diff --git a/stdio-common/_itoa.c b/stdio-common/_itoa.c index f61b23fceb3..d018313213a 100644 --- a/stdio-common/_itoa.c +++ b/stdio-common/_itoa.c @@ -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 index 00000000000..2ef398674b7 --- /dev/null +++ b/stdio-common/bug17.c @@ -0,0 +1,31 @@ +#include +#include + +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"