diff options
| author | Paul Eggert | 2015-02-08 23:12:04 -0800 |
|---|---|---|
| committer | Paul Eggert | 2015-02-08 23:12:32 -0800 |
| commit | 2f7008715326a49770fcb82003ed78eab28c0626 (patch) | |
| tree | a34a7d13109dda84089ea6082e243f27000fe671 | |
| parent | 237171731157095f5cc46b0f6f6205e3b4ba9f00 (diff) | |
| download | emacs-2f7008715326a49770fcb82003ed78eab28c0626.tar.gz emacs-2f7008715326a49770fcb82003ed78eab28c0626.zip | |
Use C99's INFINITY and NAN macros
* lread.c: Include <math.h>.
(string_to_number): Use INFINITY and NAN rather than rolling our own.
This avoids some runtime diagnostics when building with
gcc -fsanitize=undefined.
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/lread.c | 26 |
2 files changed, 10 insertions, 22 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 3b2c9a6777f..381ae6b0989 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,11 @@ | |||
| 1 | 2015-02-09 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2015-02-09 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | Use C99's INFINITY and NAN macros | ||
| 4 | * lread.c: Include <math.h>. | ||
| 5 | (string_to_number): Use INFINITY and NAN rather than rolling our own. | ||
| 6 | This avoids some runtime diagnostics when building with | ||
| 7 | gcc -fsanitize=undefined. | ||
| 8 | |||
| 3 | Fix bidi_explicit_dir_char undefined behavior | 9 | Fix bidi_explicit_dir_char undefined behavior |
| 4 | * bidi.c (bidi_explicit_dir_char): Avoid subscript error when | 10 | * bidi.c (bidi_explicit_dir_char): Avoid subscript error when |
| 5 | argument is BIDI_EOB. This can happen in bidi_level_of_next_char. | 11 | 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 <http://www.gnu.org/licenses/>. */ | |||
| 28 | #include <sys/file.h> | 28 | #include <sys/file.h> |
| 29 | #include <errno.h> | 29 | #include <errno.h> |
| 30 | #include <limits.h> /* For CHAR_BIT. */ | 30 | #include <limits.h> /* For CHAR_BIT. */ |
| 31 | #include <math.h> | ||
| 31 | #include <stat-time.h> | 32 | #include <stat-time.h> |
| 32 | #include "lisp.h" | 33 | #include "lisp.h" |
| 33 | #include "intervals.h" | 34 | #include "intervals.h" |
| @@ -3369,10 +3370,6 @@ string_to_number (char const *string, int base, bool ignore_trailing) | |||
| 3369 | bool float_syntax = 0; | 3370 | bool float_syntax = 0; |
| 3370 | double value = 0; | 3371 | double value = 0; |
| 3371 | 3372 | ||
| 3372 | /* Compute NaN and infinities using a variable, to cope with compilers that | ||
| 3373 | think they are smarter than we are. */ | ||
| 3374 | double zero = 0; | ||
| 3375 | |||
| 3376 | /* Negate the value ourselves. This treats 0, NaNs, and infinity properly on | 3373 | /* Negate the value ourselves. This treats 0, NaNs, and infinity properly on |
| 3377 | IEEE floating point hosts, and works around a formerly-common bug where | 3374 | IEEE floating point hosts, and works around a formerly-common bug where |
| 3378 | atof ("-0.0") drops the sign. */ | 3375 | atof ("-0.0") drops the sign. */ |
| @@ -3424,30 +3421,15 @@ string_to_number (char const *string, int base, bool ignore_trailing) | |||
| 3424 | { | 3421 | { |
| 3425 | state |= E_EXP; | 3422 | state |= E_EXP; |
| 3426 | cp += 3; | 3423 | cp += 3; |
| 3427 | value = 1.0 / zero; | 3424 | value = INFINITY; |
| 3428 | } | 3425 | } |
| 3429 | else if (cp[-1] == '+' | 3426 | else if (cp[-1] == '+' |
| 3430 | && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N') | 3427 | && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N') |
| 3431 | { | 3428 | { |
| 3432 | state |= E_EXP; | 3429 | state |= E_EXP; |
| 3433 | cp += 3; | 3430 | cp += 3; |
| 3434 | value = zero / zero; | 3431 | /* NAN is a "positive" NaN on all known Emacs hosts. */ |
| 3435 | 3432 | value = NAN; | |
| 3436 | /* If that made a "negative" NaN, negate it. */ | ||
| 3437 | { | ||
| 3438 | int i; | ||
| 3439 | union { double d; char c[sizeof (double)]; } | ||
| 3440 | u_data, u_minus_zero; | ||
| 3441 | u_data.d = value; | ||
| 3442 | u_minus_zero.d = -0.0; | ||
| 3443 | for (i = 0; i < sizeof (double); i++) | ||
| 3444 | if (u_data.c[i] & u_minus_zero.c[i]) | ||
| 3445 | { | ||
| 3446 | value = -value; | ||
| 3447 | break; | ||
| 3448 | } | ||
| 3449 | } | ||
| 3450 | /* Now VALUE is a positive NaN. */ | ||
| 3451 | } | 3433 | } |
| 3452 | else | 3434 | else |
| 3453 | cp = ecp; | 3435 | cp = ecp; |