From: Paul Eggert Date: Mon, 9 Feb 2015 07:12:04 +0000 (-0800) Subject: Use C99's INFINITY and NAN macros X-Git-Tag: emacs-25.0.90~2008^2~54 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2f7008715326a49770fcb82003ed78eab28c0626;p=emacs.git Use C99's INFINITY and NAN macros * lread.c: Include . (string_to_number): Use INFINITY and NAN rather than rolling our own. This avoids some runtime diagnostics when building with gcc -fsanitize=undefined. --- diff --git a/src/ChangeLog b/src/ChangeLog index 3b2c9a6777f..381ae6b0989 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2015-02-09 Paul Eggert + Use C99's INFINITY and NAN macros + * lread.c: Include . + (string_to_number): Use INFINITY and NAN rather than rolling our own. + This avoids some runtime diagnostics when building with + gcc -fsanitize=undefined. + Fix bidi_explicit_dir_char undefined behavior * bidi.c (bidi_explicit_dir_char): Avoid subscript error when argument is BIDI_EOB. This can happen in bidi_level_of_next_char. diff --git a/src/lread.c b/src/lread.c index 69ec05964be..b42849fc414 100644 --- a/src/lread.c +++ b/src/lread.c @@ -28,6 +28,7 @@ along with GNU Emacs. If not, see . */ #include #include #include /* For CHAR_BIT. */ +#include #include #include "lisp.h" #include "intervals.h" @@ -3369,10 +3370,6 @@ string_to_number (char const *string, int base, bool ignore_trailing) bool float_syntax = 0; double value = 0; - /* Compute NaN and infinities using a variable, to cope with compilers that - think they are smarter than we are. */ - double zero = 0; - /* Negate the value ourselves. This treats 0, NaNs, and infinity properly on IEEE floating point hosts, and works around a formerly-common bug where atof ("-0.0") drops the sign. */ @@ -3424,30 +3421,15 @@ string_to_number (char const *string, int base, bool ignore_trailing) { state |= E_EXP; cp += 3; - value = 1.0 / zero; + value = INFINITY; } else if (cp[-1] == '+' && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N') { state |= E_EXP; cp += 3; - value = zero / zero; - - /* If that made a "negative" NaN, negate it. */ - { - int i; - union { double d; char c[sizeof (double)]; } - u_data, u_minus_zero; - u_data.d = value; - u_minus_zero.d = -0.0; - for (i = 0; i < sizeof (double); i++) - if (u_data.c[i] & u_minus_zero.c[i]) - { - value = -value; - break; - } - } - /* Now VALUE is a positive NaN. */ + /* NAN is a "positive" NaN on all known Emacs hosts. */ + value = NAN; } else cp = ecp;