diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2016-10-09 19:21:56 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2016-10-09 19:21:56 +0200 |
commit | 525c181a5a9a95e24d2111b7792608151a40eb84 (patch) | |
tree | 8ba16eeb3fb7327e5c3c5bba9c5786d4bb6ccec1 /stdio-common | |
parent | 4dd9e35bfd35d3138bc44169baba098005bad51e (diff) | |
parent | 7bb5f8a836b916d6ebf7b6921b136e99cea2442d (diff) |
Merge commit 'refs/top-bases/t/bigmem' into t/bigmem
Diffstat (limited to 'stdio-common')
97 files changed, 521 insertions, 364 deletions
diff --git a/stdio-common/Makefile b/stdio-common/Makefile index d0bf0e1083..cc79d347bc 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1991-2015 Free Software Foundation, Inc. +# Copyright (C) 1991-2016 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 @@ -57,18 +57,36 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \ bug19 bug19a tst-popen2 scanf13 scanf14 scanf15 bug20 bug21 bug22 \ scanf16 scanf17 tst-setvbuf1 tst-grouping bug23 bug24 \ bug-vfprintf-nargs tst-long-dbl-fphex tst-fphex-wide tst-sprintf3 \ - bug25 tst-printf-round bug23-2 bug23-3 bug23-4 bug26 tst-fmemopen3 + bug25 tst-printf-round bug23-2 bug23-3 bug23-4 bug26 tst-fmemopen3 \ + tst-printf-bz18872 test-srcs = tst-unbputc tst-printf ifeq ($(run-built-tests),yes) tests-special += $(objpfx)tst-unbputc.out $(objpfx)tst-printf.out \ + $(objpfx)tst-printf-bz18872-mem.out \ $(objpfx)tst-setvbuf1-cmp.out +generated += tst-printf-bz18872.c tst-printf-bz18872.mtrace \ + tst-printf-bz18872-mem.out endif include ../Rules ifeq ($(run-built-tests),yes) +LOCALES := de_DE.ISO-8859-1 de_DE.UTF-8 en_US.ISO-8859-1 ja_JP.EUC-JP +include ../gen-locales.mk + +$(objpfx)bug14.out: $(gen-locales) +$(objpfx)scanf13.out: $(gen-locales) +$(objpfx)test-vfprintf.out: $(gen-locales) +$(objpfx)tst-grouping.out: $(gen-locales) +$(objpfx)tst-sprintf.out: $(gen-locales) +$(objpfx)tst-sscanf.out: $(gen-locales) +$(objpfx)tst-swprintf.out: $(gen-locales) +endif + +tst-printf-bz18872-ENV = MALLOC_TRACE=$(objpfx)tst-printf-bz18872.mtrace + $(objpfx)tst-unbputc.out: tst-unbputc.sh $(objpfx)tst-unbputc $(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \ $(evaluate-test) @@ -76,7 +94,15 @@ $(objpfx)tst-unbputc.out: tst-unbputc.sh $(objpfx)tst-unbputc $(objpfx)tst-printf.out: tst-printf.sh $(objpfx)tst-printf $(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \ $(evaluate-test) -endif + +# We generate this source because it requires a printf invocation with +# 10K arguments. +$(objpfx)tst-printf-bz18872.c: tst-printf-bz18872.sh + rm -f $@ && $(BASH) $^ > $@.new && mv $@.new $@ + +$(objpfx)tst-printf-bz18872-mem.out: $(objpfx)tst-printf-bz18872.out + $(common-objpfx)malloc/mtrace $(objpfx)tst-printf-bz18872.mtrace > $@; \ + $(evaluate-test) CFLAGS-vfprintf.c = -Wno-uninitialized CFLAGS-vfwprintf.c = -Wno-uninitialized @@ -88,18 +114,18 @@ CFLAGS-psignal.c = -fexceptions CFLAGS-vprintf.c = -fexceptions CFLAGS-cuserid.c = -fexceptions -CFLAGS-vfprintf.c += $(exceptions) -CFLAGS-fprintf.c += $(exceptions) -CFLAGS-printf.c += $(exceptions) -CFLAGS-vfwprintf.c += $(exceptions) -CFLAGS-vfscanf.c += $(exceptions) -CFLAGS-vfwscanf.c += $(exceptions) -CFLAGS-fscanf.c += $(exceptions) -CFLAGS-scanf.c += $(exceptions) -CFLAGS-isoc99_vfscanf.c += $(exceptions) -CFLAGS-isoc99_vscanf.c += $(exceptions) -CFLAGS-isoc99_fscanf.c += $(exceptions) -CFLAGS-isoc99_scanf.c += $(exceptions) +CFLAGS-vfprintf.c += -fexceptions +CFLAGS-fprintf.c += -fexceptions +CFLAGS-printf.c += -fexceptions +CFLAGS-vfwprintf.c += -fexceptions +CFLAGS-vfscanf.c += -fexceptions +CFLAGS-vfwscanf.c += -fexceptions +CFLAGS-fscanf.c += -fexceptions +CFLAGS-scanf.c += -fexceptions +CFLAGS-isoc99_vfscanf.c += -fexceptions +CFLAGS-isoc99_vscanf.c += -fexceptions +CFLAGS-isoc99_fscanf.c += -fexceptions +CFLAGS-isoc99_scanf.c += -fexceptions CFLAGS-errlist.c = $(fno-unit-at-a-time) CFLAGS-siglist.c = $(fno-unit-at-a-time) diff --git a/stdio-common/_i18n_number.h b/stdio-common/_i18n_number.h index 3c730447d7..324297be71 100644 --- a/stdio-common/_i18n_number.h +++ b/stdio-common/_i18n_number.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2015 Free Software Foundation, Inc. +/* Copyright (C) 2000-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.org>, 2000. diff --git a/stdio-common/_itoa.c b/stdio-common/_itoa.c index a3ae5e1f15..b05c59b014 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-2015 Free Software Foundation, Inc. + Copyright (C) 1994-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Torbjorn Granlund <tege@matematik.su.se> and Ulrich Drepper <drepper@gnu.org>. @@ -191,11 +191,8 @@ _itoa_word (_ITOA_WORD_TYPE value, char *buflim, #if _ITOA_NEEDED char * -_itoa (value, buflim, base, upper_case) - unsigned long long int value; - char *buflim; - unsigned int base; - int upper_case; +_itoa (unsigned long long int value, char *buflim, unsigned int base, + int upper_case) { const char *digits = (upper_case ? _itoa_upper_digits diff --git a/stdio-common/_itowa.c b/stdio-common/_itowa.c index dedf4b7a9d..acbb870e97 100644 --- a/stdio-common/_itowa.c +++ b/stdio-common/_itowa.c @@ -1,5 +1,5 @@ /* Internal function for converting integers to ASCII. - Copyright (C) 1994-2015 Free Software Foundation, Inc. + Copyright (C) 1994-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Torbjorn Granlund <tege@matematik.su.se> and Ulrich Drepper <drepper@gnu.org>. @@ -87,11 +87,8 @@ extern const wchar_t _itowa_upper_digits[] attribute_hidden; #if _ITOA_NEEDED wchar_t * -_itowa (value, buflim, base, upper_case) - unsigned long long int value; - wchar_t *buflim; - unsigned int base; - int upper_case; +_itowa (unsigned long long int value, wchar_t *buflim, unsigned int base, + int upper_case) { const wchar_t *digits = (upper_case ? _itowa_upper_digits : _itowa_lower_digits); diff --git a/stdio-common/_itowa.h b/stdio-common/_itowa.h index 86d65be558..a5bf6d143d 100644 --- a/stdio-common/_itowa.h +++ b/stdio-common/_itowa.h @@ -1,5 +1,5 @@ /* Internal function for converting integers to ASCII. - Copyright (C) 1994-2015 Free Software Foundation, Inc. + Copyright (C) 1994-2016 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 diff --git a/stdio-common/asprintf.c b/stdio-common/asprintf.c index 03bad44f52..5500aa90ce 100644 --- a/stdio-common/asprintf.c +++ b/stdio-common/asprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/bits/printf-ldbl.h b/stdio-common/bits/printf-ldbl.h index 36ad50d6a2..aaa092158a 100644 --- a/stdio-common/bits/printf-ldbl.h +++ b/stdio-common/bits/printf-ldbl.h @@ -1,5 +1,5 @@ /* -mlong-double-64 compatibility mode for <printf.h> functions. - Copyright (C) 2006-2015 Free Software Foundation, Inc. + Copyright (C) 2006-2016 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 diff --git a/stdio-common/bug-vfprintf-nargs.c b/stdio-common/bug-vfprintf-nargs.c index fceb5a3e49..f3cfb4a23b 100644 --- a/stdio-common/bug-vfprintf-nargs.c +++ b/stdio-common/bug-vfprintf-nargs.c @@ -1,5 +1,5 @@ /* Test for vfprintf nargs allocation overflow (BZ #13656). - Copyright (C) 2012-2015 Free Software Foundation, Inc. + Copyright (C) 2012-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Kees Cook <keescook@chromium.org>, 2012. diff --git a/stdio-common/bug26.c b/stdio-common/bug26.c index c72f914d7f..4994f9c616 100644 --- a/stdio-common/bug26.c +++ b/stdio-common/bug26.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2013-2015 Free Software Foundation, Inc. +/* Copyright (C) 2013-2016 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 diff --git a/stdio-common/ctermid.c b/stdio-common/ctermid.c index 454402dc8f..d1577897d7 100644 --- a/stdio-common/ctermid.c +++ b/stdio-common/ctermid.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 @@ -23,8 +23,7 @@ If S is not NULL, the name is copied into it (it should be at least L_ctermid bytes long), otherwise a static buffer is used. */ char * -ctermid (s) - char *s; +ctermid (char *s) { __set_errno (ENOSYS); return NULL; diff --git a/stdio-common/cuserid.c b/stdio-common/cuserid.c index 7ab5bb855b..574b46478f 100644 --- a/stdio-common/cuserid.c +++ b/stdio-common/cuserid.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 @@ -22,8 +22,7 @@ If S is not NULL, it points to a buffer of at least L_cuserid bytes into which the name is copied; otherwise, a static buffer is used. */ char * -cuserid (s) - char *s; +cuserid (char *s) { __set_errno (ENOSYS); return NULL; diff --git a/stdio-common/dprintf.c b/stdio-common/dprintf.c index 5a7011dc52..e9762e2230 100644 --- a/stdio-common/dprintf.c +++ b/stdio-common/dprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/errlist.c b/stdio-common/errlist.c index db270545fd..440a8e1920 100644 --- a/stdio-common/errlist.c +++ b/stdio-common/errlist.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/errnobug.c b/stdio-common/errnobug.c index deefd51e8d..e046222875 100644 --- a/stdio-common/errnobug.c +++ b/stdio-common/errnobug.c @@ -1,6 +1,6 @@ /* Regression test for reported old bug that errno is clobbered by the first successful output to a stream on an unseekable object. - Copyright (C) 1995-2015 Free Software Foundation, Inc. + Copyright (C) 1995-2016 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 diff --git a/stdio-common/flockfile.c b/stdio-common/flockfile.c index 6695889c2f..34c59d738e 100644 --- a/stdio-common/flockfile.c +++ b/stdio-common/flockfile.c @@ -1,5 +1,5 @@ /* Lock I/O stream. Singlethreaded version. - Copyright (C) 1996-2015 Free Software Foundation, Inc. + Copyright (C) 1996-2016 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 diff --git a/stdio-common/fprintf.c b/stdio-common/fprintf.c index 5e86bd561f..1c41b0f5a4 100644 --- a/stdio-common/fprintf.c +++ b/stdio-common/fprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/fscanf.c b/stdio-common/fscanf.c index a1a84a339c..4c10444a0a 100644 --- a/stdio-common/fscanf.c +++ b/stdio-common/fscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/ftrylockfile.c b/stdio-common/ftrylockfile.c index b197d79b15..fe871e1c5e 100644 --- a/stdio-common/ftrylockfile.c +++ b/stdio-common/ftrylockfile.c @@ -1,5 +1,5 @@ /* Try locking I/O stream. Singlethreaded version. - Copyright (C) 1996-2015 Free Software Foundation, Inc. + Copyright (C) 1996-2016 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 diff --git a/stdio-common/funlockfile.c b/stdio-common/funlockfile.c index 85cf59dab7..95fb06850b 100644 --- a/stdio-common/funlockfile.c +++ b/stdio-common/funlockfile.c @@ -1,5 +1,5 @@ /* Unlock I/O stream. Singlethreaded version. - Copyright (C) 1996-2015 Free Software Foundation, Inc. + Copyright (C) 1996-2016 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 diff --git a/stdio-common/fxprintf.c b/stdio-common/fxprintf.c index 7b2eb941e8..097265167d 100644 --- a/stdio-common/fxprintf.c +++ b/stdio-common/fxprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2015 Free Software Foundation, Inc. +/* Copyright (C) 2005-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.org>. diff --git a/stdio-common/getline.c b/stdio-common/getline.c index 9d119932db..39e4a39910 100644 --- a/stdio-common/getline.c +++ b/stdio-common/getline.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/getw.c b/stdio-common/getw.c index 9ea2e25b2c..abf5459e6f 100644 --- a/stdio-common/getw.c +++ b/stdio-common/getw.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/isoc99_fscanf.c b/stdio-common/isoc99_fscanf.c index d0d56a3235..6fe490a69d 100644 --- a/stdio-common/isoc99_fscanf.c +++ b/stdio-common/isoc99_fscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/isoc99_scanf.c b/stdio-common/isoc99_scanf.c index 00ca98835e..51f6c3c1a1 100644 --- a/stdio-common/isoc99_scanf.c +++ b/stdio-common/isoc99_scanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/isoc99_sscanf.c b/stdio-common/isoc99_sscanf.c index 6e9840862d..57207dfcf4 100644 --- a/stdio-common/isoc99_sscanf.c +++ b/stdio-common/isoc99_sscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/isoc99_vfscanf.c b/stdio-common/isoc99_vfscanf.c index bac093fa55..d4dc4360dd 100644 --- a/stdio-common/isoc99_vfscanf.c +++ b/stdio-common/isoc99_vfscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/isoc99_vscanf.c b/stdio-common/isoc99_vscanf.c index 0d35c9f7eb..2df433cbef 100644 --- a/stdio-common/isoc99_vscanf.c +++ b/stdio-common/isoc99_vscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/isoc99_vsscanf.c b/stdio-common/isoc99_vsscanf.c index dadd12565a..720f122083 100644 --- a/stdio-common/isoc99_vsscanf.c +++ b/stdio-common/isoc99_vsscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993-2015 Free Software Foundation, Inc. +/* Copyright (C) 1993-2016 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 diff --git a/stdio-common/itoa-digits.c b/stdio-common/itoa-digits.c index 3016485a2d..b819abc0ac 100644 --- a/stdio-common/itoa-digits.c +++ b/stdio-common/itoa-digits.c @@ -1,5 +1,5 @@ /* Digits. - Copyright (C) 1994-2015 Free Software Foundation, Inc. + Copyright (C) 1994-2016 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 diff --git a/stdio-common/itoa-udigits.c b/stdio-common/itoa-udigits.c index 6e41480ae0..ac303ca5a2 100644 --- a/stdio-common/itoa-udigits.c +++ b/stdio-common/itoa-udigits.c @@ -1,5 +1,5 @@ /* Digits. - Copyright (C) 1994-2015 Free Software Foundation, Inc. + Copyright (C) 1994-2016 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 diff --git a/stdio-common/itowa-digits.c b/stdio-common/itowa-digits.c index 4e229c7adb..399d57e981 100644 --- a/stdio-common/itowa-digits.c +++ b/stdio-common/itowa-digits.c @@ -1,5 +1,5 @@ /* Digits. - Copyright (C) 1994-2015 Free Software Foundation, Inc. + Copyright (C) 1994-2016 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 diff --git a/stdio-common/perror.c b/stdio-common/perror.c index f28d055414..c2bba6800e 100644 --- a/stdio-common/perror.c +++ b/stdio-common/perror.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/printf-parse.h b/stdio-common/printf-parse.h index e990354999..0f21fedc3d 100644 --- a/stdio-common/printf-parse.h +++ b/stdio-common/printf-parse.h @@ -1,5 +1,5 @@ /* Internal header for parsing printf format strings. - Copyright (C) 1995-2015 Free Software Foundation, Inc. + Copyright (C) 1995-2016 Free Software Foundation, Inc. This file is part of th GNU C Library. The GNU C Library is free software; you can redistribute it and/or diff --git a/stdio-common/printf-parsemb.c b/stdio-common/printf-parsemb.c index 1bffa0e492..66cef10b20 100644 --- a/stdio-common/printf-parsemb.c +++ b/stdio-common/printf-parsemb.c @@ -1,5 +1,5 @@ /* Helper functions for parsing printf format strings. - Copyright (C) 1995-2015 Free Software Foundation, Inc. + Copyright (C) 1995-2016 Free Software Foundation, Inc. This file is part of th GNU C Library. The GNU C Library is free software; you can redistribute it and/or diff --git a/stdio-common/printf-prs.c b/stdio-common/printf-prs.c index d66fd15f02..b51b567f10 100644 --- a/stdio-common/printf-prs.c +++ b/stdio-common/printf-prs.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 @@ -56,10 +56,7 @@ size_t -parse_printf_format (fmt, n, argtypes) - const char *fmt; - size_t n; - int *argtypes; +parse_printf_format (const char *fmt, size_t n, int *argtypes) { size_t nargs; /* Number of arguments. */ size_t max_ref_arg; /* Highest index used in a positional arg. */ diff --git a/stdio-common/printf.c b/stdio-common/printf.c index 89d0237663..acc67d2740 100644 --- a/stdio-common/printf.c +++ b/stdio-common/printf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/printf.h b/stdio-common/printf.h index 6441259737..d731216197 100644 --- a/stdio-common/printf.h +++ b/stdio-common/printf.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/printf_fp.c b/stdio-common/printf_fp.c index 3023b20183..4134f8ab89 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-2015 Free Software Foundation, Inc. + Copyright (C) 1995-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. @@ -332,7 +332,6 @@ ___printf_fp (FILE *fp, fpnum.ldbl = *(const long double *) args[0]; /* Check for special values: not a number or infinity. */ - int res; if (isnan (fpnum.ldbl)) { is_neg = signbit (fpnum.ldbl); @@ -347,9 +346,9 @@ ___printf_fp (FILE *fp, wspecial = L"nan"; } } - else if ((res = __isinfl (fpnum.ldbl))) + else if (isinf (fpnum.ldbl)) { - is_neg = res < 0; + is_neg = signbit (fpnum.ldbl); if (isupper (info->spec)) { special = "INF"; @@ -377,11 +376,9 @@ ___printf_fp (FILE *fp, fpnum.dbl = *(const double *) args[0]; /* Check for special values: not a number or infinity. */ - int res; if (isnan (fpnum.dbl)) { - union ieee754_double u = { .d = fpnum.dbl }; - is_neg = u.ieee.negative != 0; + is_neg = signbit (fpnum.dbl); if (isupper (info->spec)) { special = "NAN"; @@ -393,9 +390,9 @@ ___printf_fp (FILE *fp, wspecial = L"nan"; } } - else if ((res = __isinf (fpnum.dbl))) + else if (isinf (fpnum.dbl)) { - is_neg = res < 0; + is_neg = signbit (fpnum.dbl); if (isupper (info->spec)) { special = "INF"; diff --git a/stdio-common/printf_fphex.c b/stdio-common/printf_fphex.c index 6c3b5e9723..255c7e0372 100644 --- a/stdio-common/printf_fphex.c +++ b/stdio-common/printf_fphex.c @@ -1,5 +1,5 @@ /* Print floating point number in hexadecimal notation according to ISO C99. - Copyright (C) 1997-2015 Free Software Foundation, Inc. + Copyright (C) 1997-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -180,7 +180,7 @@ __printf_fphex (FILE *fp, } else { - if (__isinfl (fpnum.ldbl)) + if (isinf (fpnum.ldbl)) { if (isupper (info->spec)) { @@ -204,7 +204,6 @@ __printf_fphex (FILE *fp, /* Check for special values: not a number or infinity. */ if (isnan (fpnum.dbl.d)) { - negative = fpnum.dbl.ieee.negative != 0; if (isupper (info->spec)) { special = "NAN"; @@ -218,8 +217,7 @@ __printf_fphex (FILE *fp, } else { - int res = __isinf (fpnum.dbl.d); - if (res) + if (isinf (fpnum.dbl.d)) { if (isupper (info->spec)) { @@ -231,11 +229,9 @@ __printf_fphex (FILE *fp, special = "inf"; wspecial = L"inf"; } - negative = res < 0; } - else - negative = signbit (fpnum.dbl.d); } + negative = signbit (fpnum.dbl.d); } if (special) diff --git a/stdio-common/printf_size.c b/stdio-common/printf_size.c index 7dcd58e0d8..154ba9da1b 100644 --- a/stdio-common/printf_size.c +++ b/stdio-common/printf_size.c @@ -1,5 +1,5 @@ /* Print size value using units for orders of magnitude. - Copyright (C) 1997-2015 Free Software Foundation, Inc. + Copyright (C) 1997-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. Based on a proposal by Larry McVoy <lm@sgi.com>. @@ -108,7 +108,7 @@ __printf_size (FILE *fp, const struct printf_info *info, fpnum; const void *ptr = &fpnum; - int fpnum_sign = 0; + int is_neg = 0; /* "NaN" or "Inf" for the special cases. */ const char *special = NULL; @@ -117,7 +117,6 @@ __printf_size (FILE *fp, const struct printf_info *info, struct printf_info fp_info; int done = 0; int wide = info->wide; - int res; /* Fetch the argument value. */ #ifndef __NO_LONG_DOUBLE_MATH @@ -130,11 +129,11 @@ __printf_size (FILE *fp, const struct printf_info *info, { special = "nan"; wspecial = L"nan"; - // fpnum_sign = 0; Already zero + // is_neg = 0; Already zero } - else if ((res = __isinfl (fpnum.ldbl))) + else if (isinf (fpnum.ldbl)) { - fpnum_sign = res; + is_neg = signbit (fpnum.ldbl); special = "inf"; wspecial = L"inf"; } @@ -155,11 +154,11 @@ __printf_size (FILE *fp, const struct printf_info *info, { special = "nan"; wspecial = L"nan"; - // fpnum_sign = 0; Already zero + // is_neg = 0; Already zero } - else if ((res = __isinf (fpnum.dbl.d))) + else if (isinf (fpnum.dbl.d)) { - fpnum_sign = res; + is_neg = signbit (fpnum.dbl.d); special = "inf"; wspecial = L"inf"; } @@ -175,14 +174,14 @@ __printf_size (FILE *fp, const struct printf_info *info, { int width = info->prec > info->width ? info->prec : info->width; - if (fpnum_sign < 0 || info->showsign || info->space) + if (is_neg || info->showsign || info->space) --width; width -= 3; if (!info->left && width > 0) PADN (' ', width); - if (fpnum_sign < 0) + if (is_neg) outchar ('-'); else if (info->showsign) outchar ('+'); diff --git a/stdio-common/psiginfo.c b/stdio-common/psiginfo.c index 30847ea6aa..96c6e91b2a 100644 --- a/stdio-common/psiginfo.c +++ b/stdio-common/psiginfo.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2015 Free Software Foundation, Inc. +/* Copyright (C) 2009-2016 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 diff --git a/stdio-common/psignal.c b/stdio-common/psignal.c index d4473f10ca..f391ada336 100644 --- a/stdio-common/psignal.c +++ b/stdio-common/psignal.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/putw.c b/stdio-common/putw.c index 8db9a85bfe..a70d3a0d91 100644 --- a/stdio-common/putw.c +++ b/stdio-common/putw.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/reg-modifier.c b/stdio-common/reg-modifier.c index 0bb04b3b4b..9a9a678ab7 100644 --- a/stdio-common/reg-modifier.c +++ b/stdio-common/reg-modifier.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2015 Free Software Foundation, Inc. +/* Copyright (C) 2009-2016 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 @@ #include <printf.h> #include <stdlib.h> #include <wchar.h> -#include <bits/libc-lock.h> +#include <libc-lock.h> struct printf_modifier_record diff --git a/stdio-common/reg-printf.c b/stdio-common/reg-printf.c index b7226f4d9c..cd64c2abdd 100644 --- a/stdio-common/reg-printf.c +++ b/stdio-common/reg-printf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 @@ #include <printf.h> #include <stddef.h> #include <stdlib.h> -#include <bits/libc-lock.h> +#include <libc-lock.h> /* Array of functions indexed by format character. */ @@ -38,10 +38,8 @@ int __register_printf_function (int, printf_function, /* Register FUNC to be called to format SPEC specifiers. */ int -__register_printf_specifier (spec, converter, arginfo) - int spec; - printf_function converter; - printf_arginfo_size_function arginfo; +__register_printf_specifier (int spec, printf_function converter, + printf_arginfo_size_function arginfo) { if (spec < 0 || spec > (int) UCHAR_MAX) { @@ -79,10 +77,8 @@ weak_alias (__register_printf_specifier, register_printf_specifier) /* Register FUNC to be called to format SPEC specifiers. */ int -__register_printf_function (spec, converter, arginfo) - int spec; - printf_function converter; - printf_arginfo_function arginfo; +__register_printf_function (int spec, printf_function converter, + printf_arginfo_function arginfo) { return __register_printf_specifier (spec, converter, (printf_arginfo_size_function*) arginfo); diff --git a/stdio-common/reg-type.c b/stdio-common/reg-type.c index d02b5a2e75..aaaf46af30 100644 --- a/stdio-common/reg-type.c +++ b/stdio-common/reg-type.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2015 Free Software Foundation, Inc. +/* Copyright (C) 2009-2016 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 @@ -18,7 +18,7 @@ #include <errno.h> #include <printf.h> #include <stdlib.h> -#include <bits/libc-lock.h> +#include <libc-lock.h> /* Array of functions indexed by format character. */ diff --git a/stdio-common/remove.c b/stdio-common/remove.c index c1815b8dc0..7bbe476585 100644 --- a/stdio-common/remove.c +++ b/stdio-common/remove.c @@ -1,5 +1,5 @@ /* ANSI C `remove' function to delete a file or directory. Stub version. - Copyright (C) 1995-2015 Free Software Foundation, Inc. + Copyright (C) 1995-2016 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,8 +20,7 @@ #include <stdio.h> int -remove (file) - const char *file; +remove (const char *file) { __set_errno (ENOSYS); return -1; diff --git a/stdio-common/rename.c b/stdio-common/rename.c index b4e521dd89..993a96f2bd 100644 --- a/stdio-common/rename.c +++ b/stdio-common/rename.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 @@ -21,9 +21,7 @@ /* Rename the file OLD to NEW. */ int -rename (old, new) - const char *old; - const char *new; +rename (const char *old, const char *new) { if (old == NULL || new == NULL) { diff --git a/stdio-common/renameat.c b/stdio-common/renameat.c index f191fc3b54..40698025b9 100644 --- a/stdio-common/renameat.c +++ b/stdio-common/renameat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2015 Free Software Foundation, Inc. +/* Copyright (C) 2005-2016 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 @@ -22,11 +22,7 @@ /* Rename the file OLD relative to OLDFD to NEW relative to NEWFD. */ int -renameat (oldfd, old, newfd, new) - int oldfd; - const char *old; - int newfd; - const char *new; +renameat (int oldfd, const char *old, int newfd, const char *new) { if ((oldfd < 0 && oldfd != AT_FDCWD) || (newfd < 0 && newfd != AT_FDCWD)) { diff --git a/stdio-common/scanf.c b/stdio-common/scanf.c index afbfc21260..c020bb85ba 100644 --- a/stdio-common/scanf.c +++ b/stdio-common/scanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/scanf11.c b/stdio-common/scanf11.c index 451f64401b..fcf98464b4 100644 --- a/stdio-common/scanf11.c +++ b/stdio-common/scanf11.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2015 Free Software Foundation, Inc. +/* Copyright (C) 2001-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2001. diff --git a/stdio-common/scanf15.c b/stdio-common/scanf15.c index 851466b3a9..a3ab15dea2 100644 --- a/stdio-common/scanf15.c +++ b/stdio-common/scanf15.c @@ -1,6 +1,7 @@ #undef _GNU_SOURCE #define _XOPEN_SOURCE 600 #undef _LIBC +#undef _IO_MTSAFE_IO /* The following macro definitions are a hack. They word around disabling the GNU extension while still using a few internal headers. */ #define u_char unsigned char diff --git a/stdio-common/scanf17.c b/stdio-common/scanf17.c index 4478a7022f..b6c0e63ab0 100644 --- a/stdio-common/scanf17.c +++ b/stdio-common/scanf17.c @@ -1,6 +1,7 @@ #undef _GNU_SOURCE #define _XOPEN_SOURCE 600 #undef _LIBC +#undef _IO_MTSAFE_IO /* The following macro definitions are a hack. They word around disabling the GNU extension while still using a few internal headers. */ #define u_char unsigned char diff --git a/stdio-common/siglist.c b/stdio-common/siglist.c index a78c69248a..9dbceb7e39 100644 --- a/stdio-common/siglist.c +++ b/stdio-common/siglist.c @@ -1,5 +1,5 @@ /* Define list of all signal numbers and their names. - Copyright (C) 1997-2015 Free Software Foundation, Inc. + Copyright (C) 1997-2016 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 diff --git a/stdio-common/snprintf.c b/stdio-common/snprintf.c index 85ada81fb7..a3cc518976 100644 --- a/stdio-common/snprintf.c +++ b/stdio-common/snprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/sprintf.c b/stdio-common/sprintf.c index 456b3dc2f6..76f51f6c22 100644 --- a/stdio-common/sprintf.c +++ b/stdio-common/sprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/sscanf.c b/stdio-common/sscanf.c index 8930409683..993636120b 100644 --- a/stdio-common/sscanf.c +++ b/stdio-common/sscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/stdio_ext.h b/stdio-common/stdio_ext.h index 4c50bc6571..eca2b19204 100644 --- a/stdio-common/stdio_ext.h +++ b/stdio-common/stdio_ext.h @@ -1,5 +1,5 @@ /* Functions to access FILE structure internals. - Copyright (C) 2000-2015 Free Software Foundation, Inc. + Copyright (C) 2000-2016 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 diff --git a/stdio-common/stdio_lim.h.in b/stdio-common/stdio_lim.h.in index e2ef3b802c..dc9cdbedc2 100644 --- a/stdio-common/stdio_lim.h.in +++ b/stdio-common/stdio_lim.h.in @@ -1,4 +1,4 @@ -/* Copyright (C) 1994-2015 Free Software Foundation, Inc. +/* Copyright (C) 1994-2016 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 diff --git a/stdio-common/tempnam.c b/stdio-common/tempnam.c index 3b54586bd7..7a53262e9a 100644 --- a/stdio-common/tempnam.c +++ b/stdio-common/tempnam.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/tempname.c b/stdio-common/tempname.c index 32a91b0308..07102c51e7 100644 --- a/stdio-common/tempname.c +++ b/stdio-common/tempname.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 @@ -24,12 +24,8 @@ template suitable for use in __gen_tempname into TMPL, bounded by TMPL_LEN. */ int -__path_search (tmpl, tmpl_len, dir, pfx, try_tmpdir) - char *tmpl; - size_t tmpl_len; - const char *dir; - const char *pfx; - int try_tmpdir; +__path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx, + int try_tmpdir) { __set_errno (ENOSYS); return -1; @@ -46,11 +42,7 @@ stub_warning (__path_search) */ int -__gen_tempname (tmpl, suffixlen, flags, kind) - char *tmpl; - int suffixlen; - int flags; - int kind; +__gen_tempname (char *tmpl, int suffixlen, int flags, int kind) { __set_errno (ENOSYS); return -1; diff --git a/stdio-common/test-fseek.c b/stdio-common/test-fseek.c index 288cfbc5f9..455b2bea92 100644 --- a/stdio-common/test-fseek.c +++ b/stdio-common/test-fseek.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/test-fwrite.c b/stdio-common/test-fwrite.c index ce54169931..5677c6da80 100644 --- a/stdio-common/test-fwrite.c +++ b/stdio-common/test-fwrite.c @@ -1,8 +1,8 @@ #include <stdio.h> #include <string.h> -int -main (int argc, char *argv[]) +static int +do_test (void) { FILE *f = tmpfile (); char obuf[99999], ibuf[sizeof obuf]; @@ -66,3 +66,6 @@ There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\ puts ("Test succeeded."); return 0; } + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/stdio-common/test-popen.c b/stdio-common/test-popen.c index 66613888ae..caf5731940 100644 --- a/stdio-common/test-popen.c +++ b/stdio-common/test-popen.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997-2015 Free Software Foundation, Inc. +/* Copyright (C) 1997-2016 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 diff --git a/stdio-common/test-vfprintf.c b/stdio-common/test-vfprintf.c index a82a331532..b8829eaf10 100644 --- a/stdio-common/test-vfprintf.c +++ b/stdio-common/test-vfprintf.c @@ -1,5 +1,5 @@ /* Tests of *printf for very large strings. - Copyright (C) 2000-2015 Free Software Foundation, Inc. + Copyright (C) 2000-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2000. diff --git a/stdio-common/test_rdwr.c b/stdio-common/test_rdwr.c index e85404ae82..3b994d130b 100644 --- a/stdio-common/test_rdwr.c +++ b/stdio-common/test_rdwr.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/tmpfile.c b/stdio-common/tmpfile.c index e22a3f24b3..d4720a4e9a 100644 --- a/stdio-common/tmpfile.c +++ b/stdio-common/tmpfile.c @@ -1,5 +1,5 @@ /* Open a stdio stream on an anonymous temporary file. Generic/POSIX version. - Copyright (C) 1991-2015 Free Software Foundation, Inc. + Copyright (C) 1991-2016 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 diff --git a/stdio-common/tmpfile64.c b/stdio-common/tmpfile64.c index 1c5501ae43..6864c33bbe 100644 --- a/stdio-common/tmpfile64.c +++ b/stdio-common/tmpfile64.c @@ -1,5 +1,5 @@ /* Open a stdio stream on an anonymous, large temporary file. Generic version. - Copyright (C) 2012-2015 Free Software Foundation, Inc. + Copyright (C) 2012-2016 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 diff --git a/stdio-common/tmpnam.c b/stdio-common/tmpnam.c index 7a1b74675d..6f0b1d596e 100644 --- a/stdio-common/tmpnam.c +++ b/stdio-common/tmpnam.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/tmpnam_r.c b/stdio-common/tmpnam_r.c index 7423a684b7..aa26737060 100644 --- a/stdio-common/tmpnam_r.c +++ b/stdio-common/tmpnam_r.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/tst-ferror.c b/stdio-common/tst-ferror.c index 5f23002c7a..69592df048 100644 --- a/stdio-common/tst-ferror.c +++ b/stdio-common/tst-ferror.c @@ -1,7 +1,7 @@ #include <stdio.h> -int -main (int argc, char *argv[]) +static int +do_test (void) { char buf[100]; int result = 0; @@ -39,3 +39,6 @@ main (int argc, char *argv[]) } return result; } + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/stdio-common/tst-fileno.c b/stdio-common/tst-fileno.c index 8b64d33d82..a1a05a9d1b 100644 --- a/stdio-common/tst-fileno.c +++ b/stdio-common/tst-fileno.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1994-2015 Free Software Foundation, Inc. +/* Copyright (C) 1994-2016 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 diff --git a/stdio-common/tst-fmemopen.c b/stdio-common/tst-fmemopen.c index 62e8056e6f..cd151cc173 100644 --- a/stdio-common/tst-fmemopen.c +++ b/stdio-common/tst-fmemopen.c @@ -1,5 +1,5 @@ /* basic fmemopen interface testing. - Copyright (C) 2014-2015 Free Software Foundation, Inc. + Copyright (C) 2014-2016 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 diff --git a/stdio-common/tst-fmemopen2.c b/stdio-common/tst-fmemopen2.c index a2c05c12df..9d0891dcd4 100644 --- a/stdio-common/tst-fmemopen2.c +++ b/stdio-common/tst-fmemopen2.c @@ -1,5 +1,5 @@ /* fmemopen tests. - Copyright (C) 2015 Free Software Foundation, Inc. + Copyright (C) 2015-2016 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 diff --git a/stdio-common/tst-fmemopen3.c b/stdio-common/tst-fmemopen3.c index be481539ca..250f9ecc75 100644 --- a/stdio-common/tst-fmemopen3.c +++ b/stdio-common/tst-fmemopen3.c @@ -1,5 +1,5 @@ /* fmemopen tests for append and read mode. - Copyright (C) 2015 Free Software Foundation, Inc. + Copyright (C) 2015-2016 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 diff --git a/stdio-common/tst-fphex-wide.c b/stdio-common/tst-fphex-wide.c index 3b9580005d..1f4797c9f8 100644 --- a/stdio-common/tst-fphex-wide.c +++ b/stdio-common/tst-fphex-wide.c @@ -1,6 +1,6 @@ /* Test program for %a wprintf formats. This file is part of the GNU C Library. - Copyright (C) 2012-2015 Free Software Foundation, Inc. + Copyright (C) 2012-2016 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 diff --git a/stdio-common/tst-fseek.c b/stdio-common/tst-fseek.c index 8b78a73b41..2598edd0b3 100644 --- a/stdio-common/tst-fseek.c +++ b/stdio-common/tst-fseek.c @@ -1,5 +1,5 @@ /* Tests of fseek and fseeko. - Copyright (C) 2000-2015 Free Software Foundation, Inc. + Copyright (C) 2000-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2000. diff --git a/stdio-common/tst-gets.c b/stdio-common/tst-gets.c index 6a7ffb51f5..073bc54984 100644 --- a/stdio-common/tst-gets.c +++ b/stdio-common/tst-gets.c @@ -1,5 +1,5 @@ /* Tests for gets. - Copyright (C) 2001-2015 Free Software Foundation, Inc. + Copyright (C) 2001-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2001. diff --git a/stdio-common/tst-long-dbl-fphex.c b/stdio-common/tst-long-dbl-fphex.c index 2f3149f8ce..6241dfd48e 100644 --- a/stdio-common/tst-long-dbl-fphex.c +++ b/stdio-common/tst-long-dbl-fphex.c @@ -1,5 +1,5 @@ /* This file is part of the GNU C Library. - Copyright (C) 2012-2015 Free Software Foundation, Inc. + Copyright (C) 2012-2016 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 diff --git a/stdio-common/tst-popen.c b/stdio-common/tst-popen.c index 5def27f30c..94cb59d1c6 100644 --- a/stdio-common/tst-popen.c +++ b/stdio-common/tst-popen.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2015 Free Software Foundation, Inc. +/* Copyright (C) 2004-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek <jakub@redhat.com>, 2004. diff --git a/stdio-common/tst-printf-bz18872.sh b/stdio-common/tst-printf-bz18872.sh new file mode 100644 index 0000000000..b96695b400 --- /dev/null +++ b/stdio-common/tst-printf-bz18872.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# Copyright (C) 2015-2016 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 +# 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/>. + +# To test BZ #18872, we need a printf() with 10K arguments. +# Such a printf could be generated with non-trivial macro +# application, but it's simpler to generate the test source +# via this script. + +n_args=10000 + +cat <<'EOF' +#include <stdio.h> +#include <mcheck.h> + +/* + Compile do_test without optimization: GCC 4.9/5.0/6.0 takes a long time + to build this source. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67396 */ + +__attribute__ ((optimize ("-O0"))) +int do_test (void) +{ + mtrace (); + printf ( +EOF + +for ((j = 0; j < $n_args / 10; j++)); do + for ((k = 0; k < 10; k++)); do + printf '"%%%d$s" ' $((10 * $j + $k + 1)) + done + printf "\n" +done + +printf '"%%%d$s",\n' $(($n_args + 1)) + +for ((j = 0; j < $n_args / 10; j++)); do + for ((k = 0; k < 10; k++)); do + printf '"a", ' + done + printf " /* %4d */\n" $((10 * $j + $k)) +done + +printf '"\\n");' + + +cat <<'EOF' + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" + +EOF diff --git a/stdio-common/tst-printf-round.c b/stdio-common/tst-printf-round.c index 36f5e26e09..93a29b509b 100644 --- a/stdio-common/tst-printf-round.c +++ b/stdio-common/tst-printf-round.c @@ -1,5 +1,5 @@ /* Test for correct rounding of printf floating-point output. - Copyright (C) 2012-2015 Free Software Foundation, Inc. + Copyright (C) 2012-2016 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 diff --git a/stdio-common/tst-printf.c b/stdio-common/tst-printf.c index 8011033d73..2896b18ecd 100644 --- a/stdio-common/tst-printf.c +++ b/stdio-common/tst-printf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 @@ -132,8 +132,8 @@ fp_test (void) printf("%-10s\n", (char *) NULL); } -int -main (int argc, char *argv[]) +static int +do_test (void) { static char shortstr[] = "Hi, Z."; static char longstr[] = "Good morning, Doctor Chandra. This is Hal. \ @@ -393,3 +393,6 @@ rfg3 (void) printf ("got: '%s', expected: '%s'\n", buf, " 12345 1234 11145401322 321.765432 3.217654e+02 5 test-string"); } + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/stdio-common/tst-printf.sh b/stdio-common/tst-printf.sh index f4ae5e4370..5755a1bc0a 100644 --- a/stdio-common/tst-printf.sh +++ b/stdio-common/tst-printf.sh @@ -1,6 +1,6 @@ -#! /bin/sh +#!/bin/sh # Testing of printf. -# Copyright (C) 2000-2015 Free Software Foundation, Inc. +# Copyright (C) 2000-2016 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 diff --git a/stdio-common/tst-printfsz.c b/stdio-common/tst-printfsz.c index 902b2ac27b..8a3385f94d 100644 --- a/stdio-common/tst-printfsz.c +++ b/stdio-common/tst-printfsz.c @@ -7,8 +7,8 @@ #define V 12345678.12345678 -int -main (int argc, char *argv[]) +static int +do_test (void) { char buf[1024]; int result = 0; @@ -76,3 +76,6 @@ main (int argc, char *argv[]) return result; } + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/stdio-common/tst-put-error.c b/stdio-common/tst-put-error.c index 24ac068842..86e7fbd104 100644 --- a/stdio-common/tst-put-error.c +++ b/stdio-common/tst-put-error.c @@ -1,6 +1,6 @@ /* Verify that print functions return error when there is an I/O error. - Copyright (C) 2005-2015 Free Software Foundation, Inc. + Copyright (C) 2005-2016 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 diff --git a/stdio-common/tst-sprintf3.c b/stdio-common/tst-sprintf3.c index e1e5317ead..cffd1b69d0 100644 --- a/stdio-common/tst-sprintf3.c +++ b/stdio-common/tst-sprintf3.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2012-2015 Free Software Foundation, Inc. +/* Copyright (C) 2012-2016 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 diff --git a/stdio-common/tst-sscanf.c b/stdio-common/tst-sscanf.c index 9c61ab3b1b..f52cc9e07e 100644 --- a/stdio-common/tst-sscanf.c +++ b/stdio-common/tst-sscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2015 Free Software Foundation, Inc. +/* Copyright (C) 2000-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek <jakub@redhat.com>, 2000. diff --git a/stdio-common/tst-tmpnam.c b/stdio-common/tst-tmpnam.c index 63ef241deb..e3dc0776cd 100644 --- a/stdio-common/tst-tmpnam.c +++ b/stdio-common/tst-tmpnam.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1998-2015 Free Software Foundation, Inc. +/* Copyright (C) 1998-2016 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 diff --git a/stdio-common/tst-unbputc.sh b/stdio-common/tst-unbputc.sh index 3e991f2449..8156400730 100755 --- a/stdio-common/tst-unbputc.sh +++ b/stdio-common/tst-unbputc.sh @@ -1,6 +1,6 @@ -#! /bin/sh +#!/bin/sh # Testing the stdio implementation -# Copyright (C) 2000-2015 Free Software Foundation, Inc. +# Copyright (C) 2000-2016 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 @@ -28,6 +28,6 @@ ${test_program_prefix} \ ${common_objpfx}stdio-common/tst-unbputc \ 2> ${common_objpfx}stdio-common/tst-unbputc.out || status=1 -(echo -n 12 | cmp ${common_objpfx}stdio-common/tst-unbputc.out -) || status=1 +(printf 12 | cmp ${common_objpfx}stdio-common/tst-unbputc.out -) || status=1 exit $status diff --git a/stdio-common/tst-unlockedio.c b/stdio-common/tst-unlockedio.c index 3b490486d9..4e47e14f5b 100644 --- a/stdio-common/tst-unlockedio.c +++ b/stdio-common/tst-unlockedio.c @@ -1,5 +1,5 @@ /* Test for some *_unlocked stdio interfaces. - Copyright (C) 2004-2015 Free Software Foundation, Inc. + Copyright (C) 2004-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek <jakub@redhat.com>, 2004. diff --git a/stdio-common/tstgetln.c b/stdio-common/tstgetln.c index 1fd5de7f7e..d52b2bce60 100644 --- a/stdio-common/tstgetln.c +++ b/stdio-common/tstgetln.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992-2015 Free Software Foundation, Inc. +/* Copyright (C) 1992-2016 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 diff --git a/stdio-common/tstscanf.c b/stdio-common/tstscanf.c index af829f35c1..767b4d6202 100644 --- a/stdio-common/tstscanf.c +++ b/stdio-common/tstscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c index 0592e70603..6829d4dc8e 100644 --- a/stdio-common/vfprintf.c +++ b/stdio-common/vfprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 @@ -24,11 +24,12 @@ #include <string.h> #include <errno.h> #include <wchar.h> -#include <bits/libc-lock.h> +#include <libc-lock.h> #include <sys/param.h> #include <_itoa.h> #include <locale/localeinfo.h> #include <stdio.h> +#include <scratch_buffer.h> /* This code is shared between the standard stdio implementation found in GNU C library and the libio implementation originally found in @@ -1698,18 +1699,15 @@ printf_positional (_IO_FILE *s, const CHAR_T *format, int readonly_format, void *args_malloced = NULL; /* For positional argument handling. */ - struct printf_spec *specs; - - /* Track if we malloced the SPECS array and thus must free it. */ - bool specs_malloced = false; + struct scratch_buffer specsbuf; + scratch_buffer_init (&specsbuf); + struct printf_spec *specs = specsbuf.data; + size_t specs_limit = specsbuf.length / sizeof (specs[0]); /* Array with information about the needed arguments. This has to be dynamically extensible. */ size_t nspecs = 0; - /* A more or less arbitrary start value. */ - size_t nspecs_size = 32 * sizeof (struct printf_spec); - specs = alloca (nspecs_size); /* The number of arguments the format string requests. This will determine the size of the array needed to store the argument attributes. */ @@ -1746,42 +1744,15 @@ printf_positional (_IO_FILE *s, const CHAR_T *format, int readonly_format, for (const UCHAR_T *f = lead_str_end; *f != L_('\0'); f = specs[nspecs++].next_fmt) { - if (nspecs * sizeof (*specs) >= nspecs_size) + if (nspecs == specs_limit) { - /* Extend the array of format specifiers. */ - if (nspecs_size * 2 < nspecs_size) + if (!scratch_buffer_grow_preserve (&specsbuf)) { - __set_errno (ENOMEM); done = -1; goto all_done; } - struct printf_spec *old = specs; - if (__libc_use_alloca (2 * nspecs_size)) - specs = extend_alloca (specs, nspecs_size, 2 * nspecs_size); - else - { - nspecs_size *= 2; - specs = malloc (nspecs_size); - if (specs == NULL) - { - __set_errno (ENOMEM); - specs = old; - done = -1; - goto all_done; - } - } - - /* Copy the old array's elements to the new space. */ - memmove (specs, old, nspecs * sizeof (*specs)); - - /* If we had previously malloc'd space for SPECS, then - release it after the copy is complete. */ - if (specs_malloced) - free (old); - - /* Now set SPECS_MALLOCED if needed. */ - if (!__libc_use_alloca (nspecs_size)) - specs_malloced = true; + specs = specsbuf.data; + specs_limit = specsbuf.length / sizeof (specs[0]); } /* Parse the format specifier. */ @@ -2091,8 +2062,11 @@ printf_positional (_IO_FILE *s, const CHAR_T *format, int readonly_format, - specs[nspecs_done].end_of_fmt); } all_done: + if (__glibc_unlikely (args_malloced != NULL)) + free (args_malloced); if (__glibc_unlikely (workstart != NULL)) free (workstart); + scratch_buffer_free (&specsbuf); return done; } diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c index 0e204e7b32..8cd59557a6 100644 --- a/stdio-common/vfscanf.c +++ b/stdio-common/vfscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 @@ -27,8 +27,10 @@ #include <string.h> #include <wchar.h> #include <wctype.h> -#include <bits/libc-lock.h> +#include <libc-internal.h> +#include <libc-lock.h> #include <locale/localeinfo.h> +#include <scratch_buffer.h> #ifdef __GNUC__ # define HAVE_LONGLONG @@ -87,7 +89,6 @@ ? ++read_in \ : (size_t) (inchar_errno = errno)), c)) -# define MEMCPY(d, s, n) __wmemcpy (d, s, n) # define ISSPACE(Ch) iswspace (Ch) # define ISDIGIT(Ch) iswdigit (Ch) # define ISXDIGIT(Ch) iswxdigit (Ch) @@ -118,7 +119,6 @@ (void) (c != EOF \ ? ++read_in \ : (size_t) (inchar_errno = errno)), c)) -# define MEMCPY(d, s, n) memcpy (d, s, n) # define ISSPACE(Ch) __isspace_l (Ch, loc) # define ISDIGIT(Ch) __isdigit_l (Ch, loc) # define ISXDIGIT(Ch) __isxdigit_l (Ch, loc) @@ -192,6 +192,78 @@ struct ptrs_to_free char **ptrs[32]; }; +struct char_buffer { + CHAR_T *current; + CHAR_T *end; + struct scratch_buffer scratch; +}; + +/* Returns a pointer to the first CHAR_T object in the buffer. Only + valid if char_buffer_add (BUFFER, CH) has been called and + char_buffer_error (BUFFER) is false. */ +static inline CHAR_T * +char_buffer_start (const struct char_buffer *buffer) +{ + return (CHAR_T *) buffer->scratch.data; +} + +/* Returns the number of CHAR_T objects in the buffer. Only valid if + char_buffer_error (BUFFER) is false. */ +static inline size_t +char_buffer_size (const struct char_buffer *buffer) +{ + return buffer->current - char_buffer_start (buffer); +} + +/* Reinitializes BUFFER->current and BUFFER->end to cover the entire + scratch buffer. */ +static inline void +char_buffer_rewind (struct char_buffer *buffer) +{ + buffer->current = char_buffer_start (buffer); + buffer->end = buffer->current + buffer->scratch.length / sizeof (CHAR_T); +} + +/* Returns true if a previous call to char_buffer_add (BUFFER, CH) + failed. */ +static inline bool +char_buffer_error (const struct char_buffer *buffer) +{ + return __glibc_unlikely (buffer->current == NULL); +} + +/* Slow path for char_buffer_add. */ +static void +char_buffer_add_slow (struct char_buffer *buffer, CHAR_T ch) +{ + if (char_buffer_error (buffer)) + return; + size_t offset = buffer->end - (CHAR_T *) buffer->scratch.data; + if (!scratch_buffer_grow_preserve (&buffer->scratch)) + { + buffer->current = NULL; + buffer->end = NULL; + return; + } + char_buffer_rewind (buffer); + buffer->current += offset; + *buffer->current++ = ch; +} + +/* Adds CH to BUFFER. This function does not report any errors, check + for them with char_buffer_error. */ +static inline void +char_buffer_add (struct char_buffer *buffer, CHAR_T ch) + __attribute__ ((always_inline)); +static inline void +char_buffer_add (struct char_buffer *buffer, CHAR_T ch) +{ + if (__glibc_unlikely (buffer->current == buffer->end)) + char_buffer_add_slow (buffer, ch); + else + *buffer->current++ = ch; +} + /* Read formatted input from S according to the format string FORMAT, using the argument list in ARG. Return the number of assignments made, or -1 for an input error. */ @@ -262,46 +334,8 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, int skip_space = 0; /* Workspace. */ CHAR_T *tw; /* Temporary pointer. */ - CHAR_T *wp = NULL; /* Workspace. */ - size_t wpmax = 0; /* Maximal size of workspace. */ - size_t wpsize; /* Currently used bytes in workspace. */ - bool use_malloc = false; -#define ADDW(Ch) \ - do \ - { \ - if (__glibc_unlikely (wpsize == wpmax)) \ - { \ - CHAR_T *old = wp; \ - bool fits = __glibc_likely (wpmax <= SIZE_MAX / sizeof (CHAR_T) / 2); \ - size_t wpneed = MAX (UCHAR_MAX + 1, 2 * wpmax); \ - size_t newsize = fits ? wpneed * sizeof (CHAR_T) : SIZE_MAX; \ - if (!__libc_use_alloca (newsize)) \ - { \ - wp = realloc (use_malloc ? wp : NULL, newsize); \ - if (wp == NULL) \ - { \ - if (use_malloc) \ - free (old); \ - done = EOF; \ - goto errout; \ - } \ - if (! use_malloc) \ - MEMCPY (wp, old, wpsize); \ - wpmax = wpneed; \ - use_malloc = true; \ - } \ - else \ - { \ - size_t s = wpmax * sizeof (CHAR_T); \ - wp = (CHAR_T *) extend_alloca (wp, s, newsize); \ - wpmax = s / sizeof (CHAR_T); \ - if (old != NULL) \ - MEMCPY (wp, old, wpsize); \ - } \ - } \ - wp[wpsize++] = (Ch); \ - } \ - while (0) + struct char_buffer charbuf; + scratch_buffer_init (&charbuf.scratch); #ifdef __va_copy __va_copy (arg, argptr); @@ -449,7 +483,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, argpos = 0; /* Prepare temporary buffer. */ - wpsize = 0; + char_buffer_rewind (&charbuf); /* Check for a positional parameter specification. */ if (ISDIGIT ((UCHAR_T) *f)) @@ -1374,7 +1408,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, /* Check for a sign. */ if (c == L_('-') || c == L_('+')) { - ADDW (c); + char_buffer_add (&charbuf, c); if (width > 0) --width; c = inchar (); @@ -1386,7 +1420,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, if (width > 0) --width; - ADDW (c); + char_buffer_add (&charbuf, c); c = inchar (); if (width != 0 && TOLOWER (c) == L_('x')) @@ -1502,6 +1536,13 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, { /* Get the string for the digits with value N. */ #ifdef COMPILE_WSCANF + + /* wcdigits_extended[] is fully set in the loop + above, but the test for "map != NULL" is done + inside the loop here and outside the loop there. */ + DIAG_PUSH_NEEDS_COMMENT; + DIAG_IGNORE_NEEDS_COMMENT (4.7, "-Wmaybe-uninitialized"); + if (__glibc_unlikely (map != NULL)) wcdigits[n] = wcdigits_extended[n]; else @@ -1509,6 +1550,8 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, _NL_CURRENT (LC_CTYPE, _NL_CTYPE_INDIGITS0_WC + n); wcdigits[n] += from_level; + DIAG_POP_NEEDS_COMMENT; + if (c == (wint_t) *wcdigits[n]) { to_level = from_level; @@ -1641,7 +1684,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, while ((unsigned char) *cmpp == c && avail >= 0) { - ADDW (c); + char_buffer_add (&charbuf, c); if (*++cmpp == '\0') break; else @@ -1652,12 +1695,19 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, } } + if (char_buffer_error (&charbuf)) + { + __set_errno (ENOMEM); + done = EOF; + goto errout; + } + if (*cmpp != '\0') { /* We are pushing all read characters back. */ if (cmpp > thousands) { - wpsize -= cmpp - thousands; + charbuf.current -= cmpp - thousands; ungetc (c, s); while (--cmpp > thousands) ungetc_not_eof ((unsigned char) *cmpp, s); @@ -1670,14 +1720,14 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, width = avail; /* The last thousands character will be added back by - the ADDW below. */ - --wpsize; + the char_buffer_add below. */ + --charbuf.current; #endif } else break; - ADDW (c); + char_buffer_add (&charbuf, c); if (width > 0) --width; @@ -1707,7 +1757,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, while ((unsigned char) *cmpp == c && avail >= 0) { - ADDW (c); + char_buffer_add (&charbuf, c); if (*++cmpp == '\0') break; else @@ -1718,12 +1768,19 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, } } + if (char_buffer_error (&charbuf)) + { + __set_errno (ENOMEM); + done = EOF; + goto errout; + } + if (*cmpp != '\0') { /* We are pushing all read characters back. */ if (cmpp > thousands) { - wpsize -= cmpp - thousands; + charbuf.current -= cmpp - thousands; ungetc (c, s); while (--cmpp > thousands) ungetc_not_eof ((unsigned char) *cmpp, s); @@ -1736,26 +1793,35 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, width = avail; /* The last thousands character will be added back by - the ADDW below. */ - --wpsize; + the char_buffer_add below. */ + --charbuf.current; #endif } else break; } - ADDW (c); + char_buffer_add (&charbuf, c); if (width > 0) --width; c = inchar (); } - if (wpsize == 0 - || (wpsize == 1 && (wp[0] == L_('+') || wp[0] == L_('-')))) + if (char_buffer_error (&charbuf)) + { + __set_errno (ENOMEM); + done = EOF; + goto errout; + } + + if (char_buffer_size (&charbuf) == 0 + || (char_buffer_size (&charbuf) == 1 + && (char_buffer_start (&charbuf)[0] == L_('+') + || char_buffer_start (&charbuf)[0] == L_('-')))) { /* There was no number. If we are supposed to read a pointer we must recognize "(nil)" as well. */ - if (__builtin_expect (wpsize == 0 + if (__builtin_expect (char_buffer_size (&charbuf) == 0 && (flags & READ_POINTER) && (width < 0 || width >= 5) && c == '(' @@ -1765,7 +1831,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, && inchar () == L_(')'), 1)) /* We must produce the value of a NULL pointer. A single '0' digit is enough. */ - ADDW (L_('0')); + char_buffer_add (&charbuf, L_('0')); else { /* The last read character is not part of the number @@ -1780,22 +1846,32 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, ungetc (c, s); /* Convert the number. */ - ADDW (L_('\0')); + char_buffer_add (&charbuf, L_('\0')); + if (char_buffer_error (&charbuf)) + { + __set_errno (ENOMEM); + done = EOF; + goto errout; + } if (need_longlong && (flags & LONGDBL)) { if (flags & NUMBER_SIGNED) - num.q = __strtoll_internal (wp, &tw, base, flags & GROUP); + num.q = __strtoll_internal + (char_buffer_start (&charbuf), &tw, base, flags & GROUP); else - num.uq = __strtoull_internal (wp, &tw, base, flags & GROUP); + num.uq = __strtoull_internal + (char_buffer_start (&charbuf), &tw, base, flags & GROUP); } else { if (flags & NUMBER_SIGNED) - num.l = __strtol_internal (wp, &tw, base, flags & GROUP); + num.l = __strtol_internal + (char_buffer_start (&charbuf), &tw, base, flags & GROUP); else - num.ul = __strtoul_internal (wp, &tw, base, flags & GROUP); + num.ul = __strtoul_internal + (char_buffer_start (&charbuf), &tw, base, flags & GROUP); } - if (__glibc_unlikely (wp == tw)) + if (__glibc_unlikely (char_buffer_start (&charbuf) == tw)) conv_error (); if (!(flags & SUPPRESS)) @@ -1864,42 +1940,42 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, if (TOLOWER (c) == L_('n')) { /* Maybe "nan". */ - ADDW (c); + char_buffer_add (&charbuf, c); if (__builtin_expect (width == 0 || inchar () == EOF || TOLOWER (c) != L_('a'), 0)) conv_error (); if (width > 0) --width; - ADDW (c); + char_buffer_add (&charbuf, c); if (__builtin_expect (width == 0 || inchar () == EOF || TOLOWER (c) != L_('n'), 0)) conv_error (); if (width > 0) --width; - ADDW (c); + char_buffer_add (&charbuf, c); /* It is "nan". */ goto scan_float; } else if (TOLOWER (c) == L_('i')) { /* Maybe "inf" or "infinity". */ - ADDW (c); + char_buffer_add (&charbuf, c); if (__builtin_expect (width == 0 || inchar () == EOF || TOLOWER (c) != L_('n'), 0)) conv_error (); if (width > 0) --width; - ADDW (c); + char_buffer_add (&charbuf, c); if (__builtin_expect (width == 0 || inchar () == EOF || TOLOWER (c) != L_('f'), 0)) conv_error (); if (width > 0) --width; - ADDW (c); + char_buffer_add (&charbuf, c); /* It is as least "inf". */ if (width != 0 && inchar () != EOF) { @@ -1908,35 +1984,35 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, if (width > 0) --width; /* Now we have to read the rest as well. */ - ADDW (c); + char_buffer_add (&charbuf, c); if (__builtin_expect (width == 0 || inchar () == EOF || TOLOWER (c) != L_('n'), 0)) conv_error (); if (width > 0) --width; - ADDW (c); + char_buffer_add (&charbuf, c); if (__builtin_expect (width == 0 || inchar () == EOF || TOLOWER (c) != L_('i'), 0)) conv_error (); if (width > 0) --width; - ADDW (c); + char_buffer_add (&charbuf, c); if (__builtin_expect (width == 0 || inchar () == EOF || TOLOWER (c) != L_('t'), 0)) conv_error (); if (width > 0) --width; - ADDW (c); + char_buffer_add (&charbuf, c); if (__builtin_expect (width == 0 || inchar () == EOF || TOLOWER (c) != L_('y'), 0)) conv_error (); if (width > 0) --width; - ADDW (c); + char_buffer_add (&charbuf, c); } else /* Never mind. */ @@ -1948,14 +2024,14 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, exp_char = L_('e'); if (width != 0 && c == L_('0')) { - ADDW (c); + char_buffer_add (&charbuf, c); c = inchar (); if (width > 0) --width; if (width != 0 && TOLOWER (c) == L_('x')) { /* It is a number in hexadecimal format. */ - ADDW (c); + char_buffer_add (&charbuf, c); flags |= HEXA_FLOAT; exp_char = L_('p'); @@ -1972,23 +2048,29 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, while (1) { + if (char_buffer_error (&charbuf)) + { + __set_errno (ENOMEM); + done = EOF; + goto errout; + } if (ISDIGIT (c)) { - ADDW (c); + char_buffer_add (&charbuf, c); got_digit = 1; } else if (!got_e && (flags & HEXA_FLOAT) && ISXDIGIT (c)) { - ADDW (c); + char_buffer_add (&charbuf, c); got_digit = 1; } - else if (got_e && wp[wpsize - 1] == exp_char + else if (got_e && charbuf.current[-1] == exp_char && (c == L_('-') || c == L_('+'))) - ADDW (c); + char_buffer_add (&charbuf, c); else if (got_digit && !got_e && (CHAR_T) TOLOWER (c) == exp_char) { - ADDW (exp_char); + char_buffer_add (&charbuf, exp_char); got_e = got_dot = 1; } else @@ -1996,11 +2078,11 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, #ifdef COMPILE_WSCANF if (! got_dot && c == decimal) { - ADDW (c); + char_buffer_add (&charbuf, c); got_dot = 1; } else if ((flags & GROUP) != 0 && ! got_dot && c == thousands) - ADDW (c); + char_buffer_add (&charbuf, c); else { /* The last read character is not part of the number @@ -2029,7 +2111,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, { /* Add all the characters. */ for (cmpp = decimal; *cmpp != '\0'; ++cmpp) - ADDW ((unsigned char) *cmpp); + char_buffer_add (&charbuf, (unsigned char) *cmpp); if (width > 0) width = avail; got_dot = 1; @@ -2066,7 +2148,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, { /* Add all the characters. */ for (cmpp = thousands; *cmpp != '\0'; ++cmpp) - ADDW ((unsigned char) *cmpp); + char_buffer_add (&charbuf, (unsigned char) *cmpp); if (width > 0) width = avail; } @@ -2088,13 +2170,20 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, --width; } + if (char_buffer_error (&charbuf)) + { + __set_errno (ENOMEM); + done = EOF; + goto errout; + } + wctrans_t map; if (__builtin_expect ((flags & I18N) != 0, 0) /* Hexadecimal floats make no sense, fixing localized digits with ASCII letters. */ && !(flags & HEXA_FLOAT) /* Minimum requirement. */ - && (wpsize == 0 || got_dot) + && (char_buffer_size (&charbuf) == 0 || got_dot) && (map = __wctrans ("to_inpunct")) != NULL) { /* Reget the first character. */ @@ -2113,20 +2202,23 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, for localized FP numbers, then we may have localized digits. Note, we test GOT_DOT above. */ #ifdef COMPILE_WSCANF - if (wpsize == 0 || (wpsize == 1 && wcdigits[11] == decimal)) + if (char_buffer_size (&charbuf) == 0 + || (char_buffer_size (&charbuf) == 1 + && wcdigits[11] == decimal)) #else char mbdigits[12][MB_LEN_MAX + 1]; mbstate_t state; memset (&state, '\0', sizeof (state)); - bool match_so_far = wpsize == 0; + bool match_so_far = char_buffer_size (&charbuf) == 0; size_t mblen = __wcrtomb (mbdigits[11], wcdigits[11], &state); if (mblen != (size_t) -1) { mbdigits[11][mblen] = '\0'; - match_so_far |= (wpsize == strlen (decimal) - && strcmp (decimal, mbdigits[11]) == 0); + match_so_far |= + (char_buffer_size (&charbuf) == strlen (decimal) + && strcmp (decimal, mbdigits[11]) == 0); } else { @@ -2135,7 +2227,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, from a file. */ if (decimal_len <= MB_LEN_MAX) { - match_so_far |= wpsize == decimal_len; + match_so_far |= char_buffer_size (&charbuf) == decimal_len; memcpy (mbdigits[11], decimal, decimal_len + 1); } else @@ -2190,13 +2282,19 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, conversion is done correctly. */ while (1) { - if (got_e && wp[wpsize - 1] == exp_char + if (char_buffer_error (&charbuf)) + { + __set_errno (ENOMEM); + done = EOF; + goto errout; + } + if (got_e && charbuf.current[-1] == exp_char && (c == L_('-') || c == L_('+'))) - ADDW (c); - else if (wpsize > 0 && !got_e + char_buffer_add (&charbuf, c); + else if (char_buffer_size (&charbuf) > 0 && !got_e && (CHAR_T) TOLOWER (c) == exp_char) { - ADDW (exp_char); + char_buffer_add (&charbuf, exp_char); got_e = got_dot = 1; } else @@ -2210,15 +2308,15 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, if (c == wcdigits[n]) { if (n < 10) - ADDW (L_('0') + n); + char_buffer_add (&charbuf, L_('0') + n); else if (n == 11 && !got_dot) { - ADDW (decimal); + char_buffer_add (&charbuf, decimal); got_dot = 1; } else if (n == 10 && have_locthousands && ! got_dot) - ADDW (thousands); + char_buffer_add (&charbuf, thousands); else /* The last read character is not part of the number anymore. */ @@ -2245,13 +2343,14 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, width = avail; if (n < 10) - ADDW (L_('0') + n); + char_buffer_add (&charbuf, L_('0') + n); else if (n == 11 && !got_dot) { /* Add all the characters. */ for (cmpp = decimal; *cmpp != '\0'; ++cmpp) - ADDW ((unsigned char) *cmpp); + char_buffer_add (&charbuf, + (unsigned char) *cmpp); got_dot = 1; } @@ -2261,7 +2360,8 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, /* Add all the characters. */ for (cmpp = thousands; *cmpp != '\0'; ++cmpp) - ADDW ((unsigned char) *cmpp); + char_buffer_add (&charbuf, + (unsigned char) *cmpp); } else /* The last read character is not part @@ -2305,36 +2405,53 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, #endif } + if (char_buffer_error (&charbuf)) + { + __set_errno (ENOMEM); + done = EOF; + goto errout; + } + /* Have we read any character? If we try to read a number in hexadecimal notation and we have read only the `0x' prefix this is an error. */ - if (__builtin_expect (wpsize == 0 - || ((flags & HEXA_FLOAT) && wpsize == 2), 0)) + if (__glibc_unlikely (char_buffer_size (&charbuf) == 0 + || ((flags & HEXA_FLOAT) + && char_buffer_size (&charbuf) == 2))) conv_error (); scan_float: /* Convert the number. */ - ADDW (L_('\0')); + char_buffer_add (&charbuf, L_('\0')); + if (char_buffer_error (&charbuf)) + { + __set_errno (ENOMEM); + done = EOF; + goto errout; + } if ((flags & LONGDBL) && !__ldbl_is_dbl) { - long double d = __strtold_internal (wp, &tw, flags & GROUP); - if (!(flags & SUPPRESS) && tw != wp) + long double d = __strtold_internal + (char_buffer_start (&charbuf), &tw, flags & GROUP); + if (!(flags & SUPPRESS) && tw != char_buffer_start (&charbuf)) *ARG (long double *) = negative ? -d : d; } else if (flags & (LONG | LONGDBL)) { - double d = __strtod_internal (wp, &tw, flags & GROUP); - if (!(flags & SUPPRESS) && tw != wp) + double d = __strtod_internal + (char_buffer_start (&charbuf), &tw, flags & GROUP); + if (!(flags & SUPPRESS) && tw != char_buffer_start (&charbuf)) *ARG (double *) = negative ? -d : d; } else { - float d = __strtof_internal (wp, &tw, flags & GROUP); - if (!(flags & SUPPRESS) && tw != wp) + float d = __strtof_internal + (char_buffer_start (&charbuf), &tw, flags & GROUP); + if (!(flags & SUPPRESS) && tw != char_buffer_start (&charbuf)) *ARG (float *) = negative ? -d : d; } - if (__glibc_unlikely (tw == wp)) + if (__glibc_unlikely (tw == char_buffer_start (&charbuf))) conv_error (); if (!(flags & SUPPRESS)) @@ -2380,12 +2497,13 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, #else /* Fill WP with byte flags indexed by character. We will use this flag map for matching input characters. */ - if (wpmax < UCHAR_MAX + 1) + if (!scratch_buffer_set_array_size + (&charbuf.scratch, UCHAR_MAX + 1, 1)) { - wpmax = UCHAR_MAX + 1; - wp = (char *) alloca (wpmax); + done = EOF; + goto errout; } - memset (wp, '\0', UCHAR_MAX + 1); + memset (charbuf.scratch.data, '\0', UCHAR_MAX + 1); fc = *f; if (fc == ']' || fc == '-') @@ -2393,7 +2511,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, /* If ] or - appears before any char in the set, it is not the terminator or separator, but the first char in the set. */ - wp[fc] = 1; + ((char *)charbuf.scratch.data)[fc] = 1; ++f; } @@ -2404,11 +2522,11 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, /* Add all characters from the one before the '-' up to (but not including) the next format char. */ for (fc = (unsigned char) f[-2]; fc < (unsigned char) *f; ++fc) - wp[fc] = 1; + ((char *)charbuf.scratch.data)[fc] = 1; } else /* Add the character to the flag map. */ - wp[fc] = 1; + ((char *)charbuf.scratch.data)[fc] = 1; if (__glibc_unlikely (fc == '\0')) conv_error(); @@ -2537,7 +2655,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, do { - if (wp[c] == not_in) + if (((char *) charbuf.scratch.data)[c] == not_in) { ungetc_not_eof (c, s); break; @@ -2765,7 +2883,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, #else do { - if (wp[c] == not_in) + if (((char *) charbuf.scratch.data)[c] == not_in) { ungetc_not_eof (c, s); break; @@ -2905,9 +3023,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, /* Unlock stream. */ UNLOCK_STREAM (s); - if (use_malloc) - free (wp); - + scratch_buffer_free (&charbuf.scratch); if (errp != NULL) *errp |= errval; diff --git a/stdio-common/vprintf.c b/stdio-common/vprintf.c index d4b0ab5122..df66e18045 100644 --- a/stdio-common/vprintf.c +++ b/stdio-common/vprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2015 Free Software Foundation, Inc. +/* Copyright (C) 1991-2016 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 diff --git a/stdio-common/xbug.c b/stdio-common/xbug.c index 64ba314cbe..06f74aff00 100644 --- a/stdio-common/xbug.c +++ b/stdio-common/xbug.c @@ -14,18 +14,16 @@ void ReadFile (Buffer *buffer, FILE *input); #define INIT_BUFFER_SIZE 10000 -void InitBuffer(b) - Buffer *b; +void +InitBuffer (Buffer *b) { b->room = INIT_BUFFER_SIZE; b->used = 0; b->buff = (char *)malloc(INIT_BUFFER_SIZE*sizeof(char)); } -void AppendToBuffer(b, str, len) - Buffer *b; - const char *str; - int len; +void +AppendToBuffer (Buffer *b, const char *str, int len) { while (b->used + len > b->room) { b->buff = (char *)realloc(b->buff, 2*b->room*(sizeof(char))); @@ -35,9 +33,8 @@ void AppendToBuffer(b, str, len) b->used += len; } -void ReadFile(buffer, input) - Buffer *buffer; - FILE *input; +void +ReadFile (Buffer *buffer, FILE *input) { char buf[BUFSIZ + 1]; int bytes; |