diff options
Diffstat (limited to 'stdio-common')
-rw-r--r-- | stdio-common/Makefile | 13 | ||||
-rw-r--r-- | stdio-common/bug-vfprintf-nargs.c | 5 | ||||
-rw-r--r-- | stdio-common/tst-fphex-wide.c | 24 | ||||
-rw-r--r-- | stdio-common/tst-fphex.c | 57 | ||||
-rw-r--r-- | stdio-common/tst-long-dbl-fphex.c | 53 | ||||
-rw-r--r-- | stdio-common/vfprintf.c | 26 |
6 files changed, 134 insertions, 44 deletions
diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 080badc36c..8cf6335bb5 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1991-2009, 2011 Free Software Foundation, Inc. +# Copyright (C) 1991-2009, 2011, 2012 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 @@ -20,7 +20,7 @@ # subdir := stdio-common -headers := stdio_ext.h printf.h bits/printf-ldbl.h +headers := stdio_ext.h printf.h bits/printf-ldbl.h bits/stdio_lim.h routines := \ ctermid cuserid \ @@ -39,13 +39,9 @@ routines := \ isoc99_vsscanf \ psiginfo -install-others = $(inst_includedir)/bits/stdio_lim.h - include ../Makeconfig aux := errlist siglist printf-parsemb printf-parsewc fxprintf -distribute := _itoa.h _itowa.h _i18n_number.h \ - printf-parse.h stdio_lim.h.in tst-unbputc.sh tst-printf.sh tests := tstscanf test_rdwr test-popen tstgetln test-fseek \ temptest tst-fileno test-fwrite tst-ungetc tst-ferror \ @@ -60,15 +56,12 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \ tst-fwrite bug16 bug17 tst-swscanf tst-sprintf2 bug18 bug18a \ bug19 bug19a tst-popen2 scanf13 scanf14 scanf15 bug20 bug21 bug22 \ scanf16 scanf17 tst-setvbuf1 tst-grouping bug23 bug24 \ - bug-vfprintf-nargs + bug-vfprintf-nargs tst-long-dbl-fphex tst-fphex-wide test-srcs = tst-unbputc tst-printf include ../Rules -$(inst_includedir)/bits/stdio_lim.h: $(common-objpfx)bits/stdio_lim.h $(+force) - $(do-install) - ifeq ($(cross-compiling),no) .PHONY: do-tst-unbputc do-tst-printf tests: do-tst-unbputc do-tst-printf diff --git a/stdio-common/bug-vfprintf-nargs.c b/stdio-common/bug-vfprintf-nargs.c index 13c66c0486..4f621064cc 100644 --- a/stdio-common/bug-vfprintf-nargs.c +++ b/stdio-common/bug-vfprintf-nargs.c @@ -14,9 +14,8 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #include <stdio.h> #include <stdlib.h> diff --git a/stdio-common/tst-fphex-wide.c b/stdio-common/tst-fphex-wide.c new file mode 100644 index 0000000000..04d913561f --- /dev/null +++ b/stdio-common/tst-fphex-wide.c @@ -0,0 +1,24 @@ +/* Test program for %a wprintf formats. + This file is part of the GNU C Library. + Copyright (C) 2012 Free Software Foundation, Inc. + Contributed by Marek Polacek <polacek@redhat.com>, 2012. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <wchar.h> + +#define WIDE 1 + +#include "tst-fphex.c" diff --git a/stdio-common/tst-fphex.c b/stdio-common/tst-fphex.c index 212e4ed9ec..c2e8961d62 100644 --- a/stdio-common/tst-fphex.c +++ b/stdio-common/tst-fphex.c @@ -3,30 +3,48 @@ #include <stdio.h> #include <string.h> +#ifndef WIDE +# define STR_LEN strlen +# define STR_CMP strcmp +# define SPRINT snprintf +# define CHAR_T char +# define PRINT printf +# define L_(Str) Str +# define S "%s" +#else +# define STR_LEN wcslen +# define SPRINT swprintf +# define STR_CMP wcscmp +# define CHAR_T wchar_t +# define PRINT wprintf +# define L_(Str) L##Str +# define S "%ls" +#endif + struct testcase { double value; - const char *fmt; - const char *expect; + const CHAR_T *fmt; + const CHAR_T *expect; }; static const struct testcase testcases[] = { - { 0x0.0030p+0, "%a", "0x1.8p-11" }, - { 0x0.0040p+0, "%a", "0x1p-10" }, - { 0x0.0030p+0, "%040a", "0x00000000000000000000000000000001.8p-11" }, - { 0x0.0040p+0, "%040a", "0x0000000000000000000000000000000001p-10" }, - { 0x0.0040p+0, "%40a", " 0x1p-10" }, - { 0x0.0040p+0, "%#40a", " 0x1.p-10" }, - { 0x0.0040p+0, "%-40a", "0x1p-10 " }, - { 0x0.0040p+0, "%#-40a", "0x1.p-10 " }, - { 0x0.0030p+0, "%040e", "00000000000000000000000000007.324219e-04" }, - { 0x0.0040p+0, "%040e", "00000000000000000000000000009.765625e-04" }, + { 0x0.0030p+0, L_("%a"), L_("0x1.8p-11") }, + { 0x0.0040p+0, L_("%a"), L_("0x1p-10") }, + { 0x0.0030p+0, L_("%040a"), L_("0x00000000000000000000000000000001.8p-11") }, + { 0x0.0040p+0, L_("%040a"), L_("0x0000000000000000000000000000000001p-10") }, + { 0x0.0040p+0, L_("%40a"), L_(" 0x1p-10") }, + { 0x0.0040p+0, L_("%#40a"), L_(" 0x1.p-10") }, + { 0x0.0040p+0, L_("%-40a"), L_("0x1p-10 ") }, + { 0x0.0040p+0, L_("%#-40a"), L_("0x1.p-10 ") }, + { 0x0.0030p+0, L_("%040e"), L_("00000000000000000000000000007.324219e-04") }, + { 0x0.0040p+0, L_("%040e"), L_("00000000000000000000000000009.765625e-04") }, }; static int -do_test (int argc, char **argv) +do_test (void) { const struct testcase *t; int result = 0; @@ -35,12 +53,14 @@ do_test (int argc, char **argv) t < &testcases[sizeof testcases / sizeof testcases[0]]; ++t) { - char buf[1024]; - int n = snprintf (buf, sizeof buf, t->fmt, t->value); - if (n != strlen (t->expect) || strcmp (buf, t->expect) != 0) + CHAR_T buf[1024]; + int n = SPRINT (buf, sizeof buf / sizeof (buf[0]), t->fmt, t->value); + if (n != STR_LEN (t->expect) || STR_CMP (buf, t->expect) != 0) { - printf ("%s\tExpected \"%s\" (%Zu)\n\tGot \"%s\" (%d, %Zu)\n", - t->fmt, t->expect, strlen (t->expect), buf, n, strlen (buf)); + PRINT (L_("" S "\tExpected \"" S "\" (%Zu)\n\tGot \"" + S "\" (%d, %Zu)\n"), + t->fmt, t->expect, STR_LEN (t->expect), + buf, n, STR_LEN (buf)); result = 1; } } @@ -48,4 +68,5 @@ do_test (int argc, char **argv) return result; } +#define TEST_FUNCTION do_test () #include "../test-skeleton.c" diff --git a/stdio-common/tst-long-dbl-fphex.c b/stdio-common/tst-long-dbl-fphex.c new file mode 100644 index 0000000000..d879c98e88 --- /dev/null +++ b/stdio-common/tst-long-dbl-fphex.c @@ -0,0 +1,53 @@ +/* This file is part of the GNU C Library. + Copyright (C) 2012 Free Software Foundation, Inc. + Contributed by Marek Polacek <polacek@redhat.com>, 2012. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <wchar.h> + +/* Prototype for our test function. */ +static int do_test (void); + +static int +do_test (void) +{ +#ifndef NO_LONG_DOUBLE + int result = 0; + const long double x = 24.5; + wchar_t a[16]; + swprintf (a, sizeof (a), L"%La\n", x); + wchar_t A[16]; + swprintf (A, sizeof (A) / sizeof (A[0]), L"%LA\n", x); + + /* Here wprintf can return four valid variants. We must accept all + of them. */ + result |= (wmemcmp (a, L"0xc.4p+1", 8) == 0 + && wmemcmp (A, L"0XC.4P+1", 8) == 0); + result |= (wmemcmp (a, L"0x3.1p+3", 8) == 0 + && wmemcmp (A, L"0X3.1P+3", 8) == 0); + result |= (wmemcmp (a, L"0x6.2p+2", 8) == 0 + && wmemcmp (A, L"0X6.2P+2", 8) == 0); + result |= (wmemcmp (a, L"0x1.88p+4", 8) == 0 + && wmemcmp (A, L"0X1.88P+4", 8) == 0); + + return result != 1; +#else + return 0; +#endif +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c index 85d19005d2..e454927bfd 100644 --- a/stdio-common/vfprintf.c +++ b/stdio-common/vfprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2008, 2009, 2010, 2011 Free Software Foundation, Inc. +/* Copyright (C) 1991-2011, 2012 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 @@ -1706,28 +1706,28 @@ do_positional: nargs = MAX (nargs, max_ref_arg); /* Calculate total size needed to represent a single argument across all three argument-related arrays. */ - bytes_per_arg = sizeof (*args_value) + sizeof (*args_size) - + sizeof (*args_type); + bytes_per_arg = (sizeof (*args_value) + sizeof (*args_size) + + sizeof (*args_type)); /* Check for potential integer overflow. */ if (__builtin_expect (nargs > SIZE_MAX / bytes_per_arg, 0)) { - __set_errno (ERANGE); - done = -1; - goto all_done; + __set_errno (ERANGE); + done = -1; + goto all_done; } /* Allocate memory for all three argument arrays. */ if (__libc_use_alloca (nargs * bytes_per_arg)) - args_value = alloca (nargs * bytes_per_arg); + args_value = alloca (nargs * bytes_per_arg); else { - args_value = args_malloced = malloc (nargs * bytes_per_arg); - if (args_value == NULL) - { - done = -1; - goto all_done; - } + args_value = args_malloced = malloc (nargs * bytes_per_arg); + if (args_value == NULL) + { + done = -1; + goto all_done; + } } /* Set up the remaining two arrays to each point past the end of the |