glibc/stdlib
Joseph Myers e02cabecf0 Refactor strtod parsing of NaN payloads.
The nan* functions handle their string argument by constructing a
NAN(...) string on the stack as a VLA and passing it to strtod
functions.

This approach has problems discussed in bug 16961 and bug 16962: the
stack usage is unbounded, and it gives incorrect results in certain
cases where the argument is not a valid n-char-sequence.

The natural fix for both issues is to refactor the NaN payload parsing
out of strtod into a separate function that the nan* functions can
call directly, so that no temporary string needs constructing on the
stack at all.  This patch does that refactoring in preparation for
fixing those bugs (but without actually using the new functions from
nan* - which will also require exporting them from libc at version
GLIBC_PRIVATE).  This patch is not intended to change any user-visible
behavior, so no tests are added (fixes for the above bugs will of
course add tests for them).

This patch builds on my recent fixes for strtol and strtod issues in
Turkish locales.  Given those fixes, the parsing of NaN payloads is
locale-independent; thus, the new functions do not need to take a
locale_t argument.

Tested for x86_64, x86, mips64 and powerpc.

	* stdlib/strtod_nan.c: New file.
	* stdlib/strtod_nan_double.h: Likewise.
	* stdlib/strtod_nan_float.h: Likewise.
	* stdlib/strtod_nan_main.c: Likewise.
	* stdlib/strtod_nan_narrow.h: Likewise.
	* stdlib/strtod_nan_wide.h: Likewise.
	* stdlib/strtof_nan.c: Likewise.
	* stdlib/strtold_nan.c: Likewise.
	* sysdeps/ieee754/ldbl-128/strtod_nan_ldouble.h: Likewise.
	* sysdeps/ieee754/ldbl-128ibm/strtod_nan_ldouble.h: Likewise.
	* sysdeps/ieee754/ldbl-96/strtod_nan_ldouble.h: Likewise.
	* wcsmbs/wcstod_nan.c: Likewise.
	* wcsmbs/wcstof_nan.c: Likewise.
	* wcsmbs/wcstold_nan.c: Likewise.
	* stdlib/Makefile (routines): Add strtof_nan, strtod_nan and
	strtold_nan.
	* wcsmbs/Makefile (routines): Add wcstod_nan, wcstold_nan and
	wcstof_nan.
	* include/stdlib.h (__strtof_nan): Declare and use
	libc_hidden_proto.
	(__strtod_nan): Likewise.
	(__strtold_nan): Likewise.
	(__wcstof_nan): Likewise.
	(__wcstod_nan): Likewise.
	(__wcstold_nan): Likewise.
	* include/wchar.h (____wcstoull_l_internal): Declare.
	* stdlib/strtod_l.c: Do not include <ieee754.h>.
	(____strtoull_l_internal): Remove declaration.
	(STRTOF_NAN): Define macro.
	(SET_MANTISSA): Remove macro.
	(STRTOULL): Likewise.
	(____STRTOF_INTERNAL): Use STRTOF_NAN to parse NaN payload.
	* stdlib/strtof_l.c (____strtoull_l_internal): Remove declaration.
	(STRTOF_NAN): Define macro.
	(SET_MANTISSA): Remove macro.
	* sysdeps/ieee754/ldbl-128/strtold_l.c (STRTOF_NAN): Define macro.
	(SET_MANTISSA): Remove macro.
	* sysdeps/ieee754/ldbl-128ibm/strtold_l.c (STRTOF_NAN): Define
	macro.
	(SET_MANTISSA): Remove macro.
	* sysdeps/ieee754/ldbl-64-128/strtold_l.c (STRTOF_NAN): Define
	macro.
	(SET_MANTISSA): Remove macro.
	* sysdeps/ieee754/ldbl-96/strtold_l.c (STRTOF_NAN): Define macro.
	(SET_MANTISSA): Remove macro.
	* wcsmbs/wcstod_l.c (____wcstoull_l_internal): Remove declaration.
	* wcsmbs/wcstof_l.c (____wcstoull_l_internal): Likewise.
	* wcsmbs/wcstold_l.c (____wcstoull_l_internal): Likewise.
2015-11-24 22:24:52 +00:00
..
bits Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
sys
Depend
Makefile Refactor strtod parsing of NaN payloads. 2015-11-24 22:24:52 +00:00
Versions
a64l.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
abort.c Move bits/libc-lock.h and bits/libc-lockP.h out of bits/ (bug 14912). 2015-09-08 21:11:03 +00:00
abs.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
add_n.c Convert miscellaneous function definitions to prototype style. 2015-10-20 21:27:22 +00:00
addmul_1.c Convert 69 more function definitions to prototype style (line wrap cases). 2015-10-19 21:23:47 +00:00
alloca.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
at_quick_exit.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
atexit.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
atof.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
atoi.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
atol.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
atoll.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
bsearch.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
bug-fmtmsg1.c
bug-getcontext.c
bug-strtod.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
bug-strtod2.c
canonicalize.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
cmp.c Convert miscellaneous function definitions to prototype style. 2015-10-20 21:27:22 +00:00
cxa_at_quick_exit.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
cxa_atexit.c Move bits/libc-lock.h and bits/libc-lockP.h out of bits/ (bug 14912). 2015-09-08 21:11:03 +00:00
cxa_finalize.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
cxa_thread_atexit_impl.c Harden tls_dtor_list with pointer mangling [BZ #19018] 2015-10-06 13:22:56 +02:00
dbl2mpn.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
div.c Convert 29 more function definitions to prototype style (multiple parameters in one K&R parameter declaration). 2015-10-20 11:52:27 +00:00
divmod_1.c Convert miscellaneous function definitions to prototype style. 2015-10-20 21:27:22 +00:00
divrem.c Convert miscellaneous function definitions to prototype style. 2015-10-20 21:27:22 +00:00
drand48-iter.c Convert 24 more function definitions to prototype style (array parameters). 2015-10-20 11:51:03 +00:00
drand48.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
drand48_r.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
erand48.c Convert 24 more function definitions to prototype style (array parameters). 2015-10-20 11:51:03 +00:00
erand48_r.c Convert 24 more function definitions to prototype style (array parameters). 2015-10-20 11:51:03 +00:00
errno.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
exit.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
exit.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
fmtmsg.c Use __pthread_setcancelstate in libc.a 2015-09-17 16:38:54 -07:00
fmtmsg.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
fpioconst.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
fpioconst.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
gen-fpioconst.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
gen-tst-strtod-round.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
getcontext.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
getenv.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
getsubopt.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
gmp-impl.h Remove various ABS macros and replace uses with fabs (or in one case abs) 2015-05-15 11:04:40 +00:00
gmp.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
grouping.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
grouping.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
groupingwc.c
inlines.c
isomac.c fix missing ctype.h include 2015-08-06 02:59:52 -04:00
jrand48.c Convert 24 more function definitions to prototype style (array parameters). 2015-10-20 11:51:03 +00:00
jrand48_r.c Convert 24 more function definitions to prototype style (array parameters). 2015-10-20 11:51:03 +00:00
l64a.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
labs.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
lcong48.c Convert 24 more function definitions to prototype style (array parameters). 2015-10-20 11:51:03 +00:00
lcong48_r.c Convert 24 more function definitions to prototype style (array parameters). 2015-10-20 11:51:03 +00:00
ldbl2mpn.c
ldiv.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
llabs.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
lldiv.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
longlong.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
lrand48.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
lrand48_r.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
lshift.c Convert miscellaneous function definitions to prototype style. 2015-10-20 21:27:22 +00:00
makecontext.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mblen.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mbstowcs.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mbtowc.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mod_1.c Convert miscellaneous function definitions to prototype style. 2015-10-20 21:27:22 +00:00
monetary.h Fix monetary.h comment 2015-05-27 08:07:07 +05:30
mp_clz_tab.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mpn2dbl.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mpn2flt.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mpn2ldbl.c
mrand48.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mrand48_r.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
msort.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mul.c Convert miscellaneous function definitions to prototype style. 2015-10-20 21:27:22 +00:00
mul_1.c Convert 69 more function definitions to prototype style (line wrap cases). 2015-10-19 21:23:47 +00:00
mul_n.c Convert miscellaneous function definitions to prototype style. 2015-10-20 21:27:22 +00:00
nrand48.c Convert 24 more function definitions to prototype style (array parameters). 2015-10-20 11:51:03 +00:00
nrand48_r.c Convert 24 more function definitions to prototype style (array parameters). 2015-10-20 11:51:03 +00:00
old_atexit.c
on_exit.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
putenv.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
qsort.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
quick_exit.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
rand.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
rand_r.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
random.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
random_r.c Convert 69 more function definitions to prototype style (line wrap cases). 2015-10-19 21:23:47 +00:00
rpmatch.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
rshift.c Convert miscellaneous function definitions to prototype style. 2015-10-20 21:27:22 +00:00
secure-getenv.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
seed48.c Convert 24 more function definitions to prototype style (array parameters). 2015-10-20 11:51:03 +00:00
seed48_r.c Convert 24 more function definitions to prototype style (array parameters). 2015-10-20 11:51:03 +00:00
setcontext.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
setenv.c Remove GCC version conditionals on -Wmaybe-uninitialized pragmas. 2015-10-27 23:42:20 +00:00
srand48.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
srand48_r.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
stdlib.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strfmon.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strfmon_l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtod.c Convert miscellaneous function definitions to prototype style. 2015-10-20 21:27:22 +00:00
strtod_l.c Refactor strtod parsing of NaN payloads. 2015-11-24 22:24:52 +00:00
strtod_nan.c Refactor strtod parsing of NaN payloads. 2015-11-24 22:24:52 +00:00
strtod_nan_double.h Refactor strtod parsing of NaN payloads. 2015-11-24 22:24:52 +00:00
strtod_nan_float.h Refactor strtod parsing of NaN payloads. 2015-11-24 22:24:52 +00:00
strtod_nan_main.c Refactor strtod parsing of NaN payloads. 2015-11-24 22:24:52 +00:00
strtod_nan_narrow.h Refactor strtod parsing of NaN payloads. 2015-11-24 22:24:52 +00:00
strtod_nan_wide.h Refactor strtod parsing of NaN payloads. 2015-11-24 22:24:52 +00:00
strtof.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtof_l.c Refactor strtod parsing of NaN payloads. 2015-11-24 22:24:52 +00:00
strtof_nan.c Refactor strtod parsing of NaN payloads. 2015-11-24 22:24:52 +00:00
strtoimax.c
strtol.c Convert miscellaneous function definitions to prototype style. 2015-10-20 21:27:22 +00:00
strtol_l.c Fix strtol in Turkish locales (bug 19242). 2015-11-23 08:50:53 +00:00
strtold.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtold_l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtold_nan.c Refactor strtod parsing of NaN payloads. 2015-11-24 22:24:52 +00:00
strtoll.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtoll_l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtoul.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtoul_l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtoull.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtoull_l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtoumax.c
sub_n.c Convert miscellaneous function definitions to prototype style. 2015-10-20 21:27:22 +00:00
submul_1.c Convert 69 more function definitions to prototype style (line wrap cases). 2015-10-19 21:23:47 +00:00
swapcontext.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
system.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
tens_in_limb.c
test-a64l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
test-canon.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
test-canon2.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
testdiv.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
testdiv.input
testmb.c
testmb2.c
testrand.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
testsort.c
tst-atof1.c
tst-atof2.c
tst-bsearch.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-environ.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-fmtmsg.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-fmtmsg.sh Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-limits.c Fix a couple of -Wundef warnings. 2014-12-29 23:14:38 -05:00
tst-makecontext.c S390: Fix "backtrace() returns infinitely deep stack frames with makecontext()" [BZ #18508]. 2015-07-07 16:11:14 +02:00
tst-makecontext2.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-makecontext3.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-putenv.c
tst-putenvmod.c
tst-qsort.c
tst-qsort2.c stdlib/tst-qsort2.c: Fix off-by-one argc interpretation error 2014-06-20 21:29:33 +01:00
tst-rand48-2.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-rand48.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-random.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-random2.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-secure-getenv.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-setcontext.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-setcontext2.c S/390: Fix setcontext/swapcontext which are not restoring sigmask. 2015-03-12 11:08:11 +01:00
tst-setcontext3.c Bug 18125: Call exit after last linked context. 2015-05-08 11:29:38 -04:00
tst-setcontext3.sh Fix stdlib/tst-setcontext3 with dash [BZ#18418] 2015-05-17 08:48:08 -03:00
tst-strtod-nan-locale-main.c Fix strtod ("NAN(I)") in Turkish locales (bug 19266). 2015-11-24 22:21:59 +00:00
tst-strtod-nan-locale.c Fix strtod ("NAN(I)") in Turkish locales (bug 19266). 2015-11-24 22:21:59 +00:00
tst-strtod-overflow.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-strtod-round-data Fix strtof decimal rounding close to half least subnormal (bug 18247). 2015-04-10 20:45:30 +00:00
tst-strtod-round.c Fix strtof decimal rounding close to half least subnormal (bug 18247). 2015-04-10 20:45:30 +00:00
tst-strtod-underflow.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-strtod.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
tst-strtod2.c
tst-strtod3.c
tst-strtod4.c
tst-strtod5.c
tst-strtod6.c
tst-strtol-locale-main.c Fix strtol in Turkish locales (bug 19242). 2015-11-23 08:50:53 +00:00
tst-strtol-locale.c Fix strtol in Turkish locales (bug 19242). 2015-11-23 08:50:53 +00:00
tst-strtol.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
tst-strtoll.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
tst-system.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-tininess.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-tls-atexit-lib.c Remove Linuxism from tst-tls-atexit 2015-07-21 07:14:17 +05:30
tst-tls-atexit-nodelete.c Also use l_tls_dtor_count to decide on object unload (BZ #18657) 2015-07-23 11:16:18 +05:30
tst-tls-atexit.c Also use l_tls_dtor_count to decide on object unload (BZ #18657) 2015-07-23 11:16:18 +05:30
tst-unsetenv1.c
tst-xpg-basename.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
ucontext.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
udiv_qrnnd.c
wcstoimax.c
wcstombs.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
wcstoumax.c
wctomb.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
xpg_basename.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00