diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | stdio-common/Makefile | 4 | ||||
-rw-r--r-- | stdio-common/_itoa.c | 5 | ||||
-rw-r--r-- | stdio-common/bug17.c | 31 |
4 files changed, 44 insertions, 3 deletions
@@ -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-19 Ulrich Drepper <drepper@redhat.com> * iconvdata/brf.c: New file. diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 37bcdb3bc8..98220550f4 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1991-2002,2003,2004,2005,2006 Free Software Foundation, Inc. +# Copyright (C) 1991-2006, 2007 Free Software Foundation, Inc. # This file is part of the GNU C Library. # The GNU C Library is free software; you can redistribute it and/or @@ -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 f61b23fceb..285fde2ab9 100644 --- a/stdio-common/_itoa.c +++ b/stdio-common/_itoa.c @@ -1,5 +1,5 @@ /* Internal function for converting integers to ASCII. - Copyright (C) 1994, 1995, 1996, 1999, 2000, 2002, 2003, 2004 + Copyright (C) 1994, 1995, 1996, 1999, 2000, 2002, 2003, 2004, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Torbjorn Granlund <tege@matematik.su.se> @@ -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 0000000000..2ef398674b --- /dev/null +++ b/stdio-common/bug17.c @@ -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" |