diff options
| author | Andreas Schwab <schwab@redhat.com> | 2011-01-18 10:48:36 +0100 |
|---|---|---|
| committer | Andreas Schwab <schwab@redhat.com> | 2011-01-18 14:56:03 +0100 |
| commit | 11be2acce8384212388dd442c7f4eaa7b4a5f1a1 (patch) | |
| tree | daab5c3c35637b402dc6e19d50a7d45569f0042e /stdio-common | |
| parent | a6be5cf5459eeb8359e5fa192e9dc397c02102bf (diff) | |
| parent | 6392473fe970b0cdace62f31000a83ba0fcf6161 (diff) | |
| download | glibc-11be2acce8384212388dd442c7f4eaa7b4a5f1a1.tar.xz glibc-11be2acce8384212388dd442c7f4eaa7b4a5f1a1.zip | |
Merge remote branch 'origin/master' into fedora/master
Diffstat (limited to 'stdio-common')
| -rw-r--r-- | stdio-common/Makefile | 5 | ||||
| -rw-r--r-- | stdio-common/printf_fp.c | 23 | ||||
| -rw-r--r-- | stdio-common/tst-grouping.c | 83 | ||||
| -rw-r--r-- | stdio-common/vfprintf.c | 18 |
4 files changed, 114 insertions, 15 deletions
diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 9cbf14385c..6aabfb6b54 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1991-2006, 2007, 2008, 2009 Free Software Foundation, Inc. +# Copyright (C) 1991-2009, 2011 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 @@ -60,7 +60,7 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \ tst-popen tst-unlockedio tst-fmemopen2 tst-put-error tst-fgets \ tst-fwrite bug16 bug17 tst-swscanf tst-sprintf2 bug18 bug18a \ bug19 bug19a tst-popen2 scanf13 scanf14 scanf15 bug20 bug21 bug22 \ - scanf16 scanf17 tst-setvbuf1 + scanf16 scanf17 tst-setvbuf1 tst-grouping test-srcs = tst-unbputc tst-printf @@ -128,6 +128,7 @@ test-vfprintf-ENV = LOCPATH=$(common-objpfx)localedata scanf13-ENV = LOCPATH=$(common-objpfx)localedata bug14-ENV = LOCPATH=$(common-objpfx)localedata bug15-ENV = LOCPATH=$(common-objpfx)localedata +tst-grouping-ENV = LOCPATH=$(common-objpfx)localedata ifneq (,$(filter %REENTRANT, $(defines))) CPPFLAGS += -D_IO_MTSAFE_IO diff --git a/stdio-common/printf_fp.c b/stdio-common/printf_fp.c index b60ddecef0..e9ff1684ce 100644 --- a/stdio-common/printf_fp.c +++ b/stdio-common/printf_fp.c @@ -1,5 +1,5 @@ /* Floating point output for `printf'. - Copyright (C) 1995-2003, 2006, 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 1995-2003, 2006-2008, 2011 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. @@ -884,7 +884,9 @@ ___printf_fp (FILE *fp, /* Guess the number of groups we will make, and thus how many spaces we need for separator characters. */ ngroups = __guess_grouping (intdig_max, grouping); - chars_needed += ngroups; + /* Allocate one more character in case rounding increases the + number of groups. */ + chars_needed += ngroups + 1; } /* Allocate buffer for output. We need two more because while rounding @@ -1088,9 +1090,16 @@ ___printf_fp (FILE *fp, --wcp; if (grouping) - /* Add in separator characters, overwriting the same buffer. */ - wcp = group_number (wstartp, wcp, intdig_no, grouping, thousands_sepwc, - ngroups); + { + /* Rounding might have changed the number of groups. We allocated + enough memory but we need here the correct number of groups. */ + if (intdig_no != intdig_max) + ngroups = __guess_grouping (intdig_no, grouping); + + /* Add in separator characters, overwriting the same buffer. */ + wcp = group_number (wstartp, wcp, intdig_no, grouping, thousands_sepwc, + ngroups); + } /* Write the exponent if it is needed. */ if (type != 'f') @@ -1210,7 +1219,7 @@ ___printf_fp (FILE *fp, tmpptr = buffer; if (__builtin_expect (info->i18n, 0)) - { + { #ifdef COMPILE_WPRINTF wstartp = _i18n_number_rewrite (wstartp, wcp, wbuffer + wbuffer_to_alloc); @@ -1224,7 +1233,7 @@ ___printf_fp (FILE *fp, assert ((uintptr_t) buffer <= (uintptr_t) tmpptr); assert ((uintptr_t) tmpptr < (uintptr_t) buffer_end); #endif - } + } PRINT (tmpptr, wstartp, wide ? wcp - wstartp : cp - tmpptr); diff --git a/stdio-common/tst-grouping.c b/stdio-common/tst-grouping.c new file mode 100644 index 0000000000..e8f4b8c4db --- /dev/null +++ b/stdio-common/tst-grouping.c @@ -0,0 +1,83 @@ +/* BZ 12394, test by Bruno Haible. */ +#include <locale.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + + +static int +do_test (void) +{ + char buf1[1000]; + char buf2[1000]; + int result = 0; + + if (setlocale (LC_NUMERIC, "de_DE.UTF-8") == NULL) + return 1; + + sprintf (buf1, "%'.2f", 999.996); + sprintf (buf2, "%'.2f", 1000.004); + printf ("%d: \"%s\" vs \"%s\"\n", __LINE__, buf1, buf2); + if (strcmp (buf1, buf2) != 0) + result |= 2; + + sprintf (buf1, "%'.2f", 999999.996); + sprintf (buf2, "%'.2f", 1000000.004); + printf ("%d: \"%s\" vs \"%s\"\n", __LINE__, buf1, buf2); + if (strcmp (buf1, buf2) != 0) + result |= 2; + + sprintf (buf1, "%'.2f", 999999999.996); + sprintf (buf2, "%'.2f", 1000000000.004); + printf ("%d: \"%s\" vs \"%s\"\n", __LINE__, buf1, buf2); + if (strcmp (buf1, buf2) != 0) + result |= 2; + + sprintf (buf1, "%'.2f", 999999999999.996); + sprintf (buf2, "%'.2f", 1000000000000.004); + printf ("%d: \"%s\" vs \"%s\"\n", __LINE__, buf1, buf2); + if (strcmp (buf1, buf2) != 0) + result |= 2; + + sprintf (buf1, "%'.2f", 999999999999999.996); + sprintf (buf2, "%'.2f", 1000000000000000.004); + printf ("%d: \"%s\" vs \"%s\"\n", __LINE__, buf1, buf2); + if (strcmp (buf1, buf2) != 0) + result |= 2; + + sprintf (buf1, "%'.5g", 999.996); + sprintf (buf2, "%'.5g", 1000.004); + printf ("%d: \"%s\" vs \"%s\"\n", __LINE__, buf1, buf2); + if (strcmp (buf1, buf2) != 0) + result |= 4; + + sprintf (buf1, "%'.4g", 9999.996); + sprintf (buf2, "%'.4g", 10000.004); + printf ("%d: \"%s\" vs \"%s\"\n", __LINE__, buf1, buf2); + if (strcmp (buf1, buf2) != 0) + result |= 8; + + sprintf (buf1, "%'.5g", 99999.996); + sprintf (buf2, "%'.5g", 100000.004); + printf ("%d: \"%s\" vs \"%s\"\n", __LINE__, buf1, buf2); + if (strcmp (buf1, buf2) != 0) + result |= 8; + + sprintf (buf1, "%'.6g", 999999.996); + sprintf (buf2, "%'.6g", 1000000.004); + printf ("%d: \"%s\" vs \"%s\"\n", __LINE__, buf1, buf2); + if (strcmp (buf1, buf2) != 0) + result |= 8; + + sprintf (buf1, "%'.7g", 9999999.996); + sprintf (buf2, "%'.7g", 10000000.004); + printf ("%d: \"%s\" vs \"%s\"\n", __LINE__, buf1, buf2); + if (strcmp (buf1, buf2) != 0) + result |= 8; + + return result; +} + + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c index bd2609eaff..93adb11e14 100644 --- a/stdio-common/vfprintf.c +++ b/stdio-common/vfprintf.c @@ -329,7 +329,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) REF (form_floathex), /* for 'A', 'a' */ \ REF (mod_ptrdiff_t), /* for 't' */ \ REF (mod_intmax_t), /* for 'j' */ \ - REF (flag_i18n), /* for 'I' */ \ + REF (flag_i18n), /* for 'I' */ \ }; \ /* Step 1: after processing width. */ \ static JUMP_TABLE_TYPE step1_jumps[30] = \ @@ -540,7 +540,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) if (is_long_num) \ signed_number = va_arg (ap, long int); \ else if (is_char) \ - signed_number = (signed char) va_arg (ap, unsigned int); \ + signed_number = (signed char) va_arg (ap, unsigned int); \ else if (!is_short) \ signed_number = va_arg (ap, int); \ else \ @@ -636,7 +636,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) if (is_long_num) \ number.word = va_arg (ap, unsigned long int); \ else if (is_char) \ - number.word = (unsigned char) va_arg (ap, unsigned int); \ + number.word = (unsigned char) va_arg (ap, unsigned int); \ else if (!is_short) \ number.word = va_arg (ap, unsigned int); \ else \ @@ -830,7 +830,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) \ LABEL (form_floathex): \ { \ - /* Floating point number printed as hexadecimal number. */ \ + /* Floating point number printed as hexadecimal number. */ \ const void *ptr; \ int function_done; \ \ @@ -987,7 +987,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) --width; \ if (!left) \ PAD (L' '); \ - if (fspec == NULL) \ + if (fspec == NULL) \ outchar (va_arg (ap, wchar_t)); \ else \ outchar (args_value[fspec->data_arg].pa_wchar); \ @@ -1209,7 +1209,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) \ if (len == (size_t) -1) \ { \ - /* Illegal wide-character string. */ \ + /* Illegal wide-character string. */ \ done = -1; \ goto all_done; \ } \ @@ -1286,6 +1286,12 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) if (*f == L_('\0')) goto all_done; + /* Use the slow path in case any printf handler is registered. */ + if (__builtin_expect (__printf_function_table != NULL + || __printf_modifier_table != NULL + || __printf_va_arg_table != NULL, 0)) + goto do_positional; + /* Process whole format string. */ do { |
