libc/newlib/libc/stdlib
Corinna Vinschen 27652b608d strtod: Convert 64 bit double to 64 bit int during computation
The gdtoa implementation uses the type long, defined as Long, in lots
of code.  For historical reason newlib defines Long as int32_t instead.

This works fine, as long as floating point exceptions are not enabled.
The conversion to 32 bit int can lead to a FE_INVALID situation.

Example:

  const char *str = "121645100408832000.0";
  char *ptr;

  feenableexcept (FE_INVALID);
  strtod (str, &ptr);

This leads to the following situation in strtod

  double aadj;
  Long L;

  [...]
  L = (Long)aadj;

For instance, on x86_64 the code here is

  cvttsd2si %xmm0,%eax

At this point, aadj is 2529648000.0 in our example.  The conversion to
32 bit %eax results in a negative int value, thus the conversion is
invalid.  With feenableexcept (FE_INVALID), a SIGFPE is raised.

Fix this by always using 64 bit ints here if double is not a 32 bit type
to avoid this type of FP exceptions.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-04-09 11:31:04 +02:00
..
Makefile.am Importing wcstoumax inttypes method from FreeBSD. 2017-08-02 13:02:26 +02:00
Makefile.in makedoc: make errors visible 2017-12-07 11:54:11 +00:00
_Exit.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
__adjust.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
__atexit.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
__call_atexit.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
__exp10.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
__ten_mu.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
a64l.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
abort.c ansification: remove _VOID 2018-01-17 11:47:20 -06:00
abs.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
aligned_alloc.c C11 aligned_alloc() implementation 2015-10-19 14:10:33 +02:00
arc4random.c Only define static locks in multithreaded mode 2017-02-13 17:04:17 -05:00
arc4random.h Only define static locks in multithreaded mode 2017-02-13 17:04:17 -05:00
arc4random_uniform.c Add arc4random() etc. from OpenBSD 5.8 2016-03-18 12:33:41 +01:00
assert.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
atexit.c ansification: remove _EXFNPTR, _EXPARM 2018-01-17 11:47:27 -06:00
atexit.h ansification: remove _PTR 2018-01-17 11:47:16 -06:00
atof.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
atoff.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
atoi.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
atol.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
atoll.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
btowc.c Consolidate wctomb/mbtowc calls for POSIX-1.2008 2016-08-15 10:56:57 +02:00
calloc.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
chacha_private.h Cleanup macros in chacha_private.h to be target-type independent 2016-03-18 21:20:06 +01:00
cxa_atexit.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
cxa_finalize.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
div.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
drand48.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
dtoa.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
dtoastub.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
ecvtbuf.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
efgcvt.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
environ.c
envlock.c stdlib: remove TRAD_SYNOPSIS 2017-12-01 03:41:52 -06:00
eprintf.c
erand48.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
exit.c Fix syntax error in exit.c 2018-01-19 19:58:10 +01:00
gd_qnan.h 2014-03-21 Maciej W. Rozycki <macro@codesourcery.com> 2014-03-21 21:27:29 +00:00
gdtoa-gethex.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
gdtoa-hexnan.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
gdtoa.h Import correctly working strtold from David M. Gay. 2015-11-20 18:14:58 +01:00
getenv.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
getenv_r.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
getopt.c * newlib/libc/stdlib/getopt.c (getopt_internal): Add missing braces. 2013-11-13 20:04:18 +00:00
getsubopt.3
getsubopt.c
imaxabs.c Importing imaxabs inttypes method from FreeBSD. 2017-07-28 12:23:08 +02:00
imaxdiv.c Importing imaxdiv inttypes method from FreeBSD. 2017-07-28 12:23:10 +02:00
itoa.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
jrand48.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
l64a.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
labs.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
lcong48.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
ldiv.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
ldtoa.c ansification: remove _CONST 2018-01-17 11:47:08 -06:00
llabs.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
lldiv.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
local.h ansification: remove _EXFUN, _EXFUN_NOTHROW 2018-01-17 11:47:29 -06:00
lrand48.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
malign.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
malloc.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
mallocr.c
mbctype.h ansification: remove _EXFUN, _EXFUN_NOTHROW 2018-01-17 11:47:29 -06:00
mblen.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
mblen_r.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
mbrlen.c 2013-11-26 Julio Gutierrez <jgutleyva@gmail.com> 2013-11-26 17:21:01 +00:00
mbrtowc.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
mbsinit.c
mbsnrtowcs.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
mbsrtowcs.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
mbstowcs.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
mbstowcs_r.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
mbtowc.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
mbtowc_r.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
mlock.c stdlib: remove TRAD_SYNOPSIS 2017-12-01 03:41:52 -06:00
mprec.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
mprec.h ansification: remove _EXFUN, _EXFUN_NOTHROW 2018-01-17 11:47:29 -06:00
mrand48.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
msize.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
mstats.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
mtrim.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
nano-mallocr.c Add prototype to _malloc_lock() and *unlock() to malloc.h, and inlude this from nano-mallocr.c 2018-02-16 12:16:07 +01:00
nrand48.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
on_exit.c ansification: remove _EXFNPTR, _EXPARM 2018-01-17 11:47:27 -06:00
on_exit_args.c Add static instance of _on_exit_args for _REENT_SMALL platforms. 2015-12-21 11:49:28 -05:00
on_exit_args.h Add static instance of _on_exit_args for _REENT_SMALL platforms. 2015-12-21 11:49:28 -05:00
putenv.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
putenv_r.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
quick_exit.c Only define static locks in multithreaded mode 2017-02-13 17:04:17 -05:00
rand.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
rand48.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
rand48.h ansification: remove _EXFUN, _EXFUN_NOTHROW 2018-01-17 11:47:29 -06:00
rand_r.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
random.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
realloc.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
reallocarray.c Add BSD-specific reallocarray() 2017-04-04 12:19:18 +02:00
reallocf.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
rpmatch.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
sb_charsets.c Actually return value from __cp_index 2016-10-22 21:08:44 +02:00
seed48.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
setenv.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
setenv_r.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
srand48.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
std.h ansification: remove _HAVE_STDC 2018-01-17 11:47:30 -06:00
stdlib.tex Add simple versions of random() and srandom() 2016-03-28 22:39:50 -05:00
strtod.c strtod: Convert 64 bit double to 64 bit int during computation 2018-04-09 11:31:04 +02:00
strtodg.c Implement strto[dflu]_l/wcsto[dflu]_l 2016-08-15 17:35:21 +02:00
strtoimax.c Importing strtoimax inttypes method from FreeBSD. 2017-08-02 13:02:26 +02:00
strtol.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strtold.c Implement strto[dflu]_l/wcsto[dflu]_l 2016-08-15 17:35:21 +02:00
strtoll.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strtoll_r.c Implement strto[dflu]_l/wcsto[dflu]_l 2016-08-15 17:35:21 +02:00
strtorx.c Implement strto[dflu]_l/wcsto[dflu]_l 2016-08-15 17:35:21 +02:00
strtoul.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strtoull.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strtoull_r.c Implement strto[dflu]_l/wcsto[dflu]_l 2016-08-15 17:35:21 +02:00
strtoumax.c Importing strtoumax inttypes method from FreeBSD. 2017-08-02 13:02:26 +02:00
system.c ansification: remove _EXFUN, _EXFUN_NOTHROW 2018-01-17 11:47:29 -06:00
utoa.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
valloc.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcrtomb.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcsnrtombs.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcsrtombs.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcstod.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcstoimax.c Importing wcstoimax inttypes method from FreeBSD. 2017-08-02 13:02:26 +02:00
wcstol.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcstold.c Avoid "implicit declaration of function ‘strtold_l’" in wcstold.c 2016-08-16 16:21:19 +02:00
wcstoll.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcstoll_r.c Implement strto[dflu]_l/wcsto[dflu]_l 2016-08-15 17:35:21 +02:00
wcstombs.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcstombs_r.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcstoul.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcstoull.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcstoull_r.c Implement strto[dflu]_l/wcsto[dflu]_l 2016-08-15 17:35:21 +02:00
wcstoumax.c Importing wcstoumax inttypes method from FreeBSD. 2017-08-02 13:02:26 +02:00
wctob.c Consolidate wctomb/mbtowc calls for POSIX-1.2008 2016-08-15 10:56:57 +02:00
wctomb.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wctomb_r.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00