diff options
| author | Paul Eggert | 2019-04-22 11:40:13 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-04-22 11:43:28 -0700 |
| commit | 4bf3c94939406de6610cc83476adaed789826623 (patch) | |
| tree | 2870d7e865baebb00b89b791801c969683e56a36 /src | |
| parent | 981470e3590534a4d2947dfe5626cae832c6502d (diff) | |
| download | emacs-4bf3c94939406de6610cc83476adaed789826623.tar.gz emacs-4bf3c94939406de6610cc83476adaed789826623.zip | |
Go back to old way of checking json int range
Although the lisp.h macros really need improvement,
INTEGER_TO_INT is not the right way to go about it, as it
causes conversion from intmax_t to uintmax_t and back again,
which can cause a signal if the value is negative.
* src/lisp.h (INTEGER_TO_INT, ranged_integer_to_int)
(ranged_integer_to_uint): Remove, reverting recent changes to
this file.
* src/json.c (lisp_to_json): Revert to previous code,
as the change messes up with uintmax_t<->intmax_t conversion.
Diffstat (limited to 'src')
| -rw-r--r-- | src/json.c | 9 | ||||
| -rw-r--r-- | src/lisp.h | 27 |
2 files changed, 8 insertions, 28 deletions
diff --git a/src/json.c b/src/json.c index 16500bce72d..256d485eead 100644 --- a/src/json.c +++ b/src/json.c | |||
| @@ -495,7 +495,14 @@ lisp_to_json (Lisp_Object lisp, struct json_configuration *conf) | |||
| 495 | else if (EQ (lisp, Qt)) | 495 | else if (EQ (lisp, Qt)) |
| 496 | return json_check (json_true ()); | 496 | return json_check (json_true ()); |
| 497 | else if (INTEGERP (lisp)) | 497 | else if (INTEGERP (lisp)) |
| 498 | return json_check (json_integer (INTEGER_TO_INT (lisp, json_int_t))); | 498 | { |
| 499 | intmax_t low = TYPE_MINIMUM (json_int_t); | ||
| 500 | intmax_t high = TYPE_MAXIMUM (json_int_t); | ||
| 501 | intmax_t value; | ||
| 502 | if (! (integer_to_intmax (lisp, &value) && low <= value && value <= high)) | ||
| 503 | args_out_of_range_3 (lisp, make_int (low), make_int (high)); | ||
| 504 | return json_check (json_integer (value)); | ||
| 505 | } | ||
| 499 | else if (FLOATP (lisp)) | 506 | else if (FLOATP (lisp)) |
| 500 | return json_check (json_real (XFLOAT_DATA (lisp))); | 507 | return json_check (json_real (XFLOAT_DATA (lisp))); |
| 501 | else if (STRINGP (lisp)) | 508 | else if (STRINGP (lisp)) |
diff --git a/src/lisp.h b/src/lisp.h index ee5a8481ae8..d803f160006 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -2640,13 +2640,6 @@ make_uint (uintmax_t n) | |||
| 2640 | #define INT_TO_INTEGER(expr) \ | 2640 | #define INT_TO_INTEGER(expr) \ |
| 2641 | (EXPR_SIGNED (expr) ? make_int (expr) : make_uint (expr)) | 2641 | (EXPR_SIGNED (expr) ? make_int (expr) : make_uint (expr)) |
| 2642 | 2642 | ||
| 2643 | /* Return the integral value of NUM. If NUM is too big for TYPE, | ||
| 2644 | signal an error. */ | ||
| 2645 | #define INTEGER_TO_INT(num, type) \ | ||
| 2646 | (TYPE_SIGNED (type) \ | ||
| 2647 | ? ranged_integer_to_int ((num), TYPE_MINIMUM (type), TYPE_MAXIMUM (type)) \ | ||
| 2648 | : ranged_integer_to_uint ((num), TYPE_MAXIMUM (type))) | ||
| 2649 | |||
| 2650 | 2643 | ||
| 2651 | /* Forwarding pointer to an int variable. | 2644 | /* Forwarding pointer to an int variable. |
| 2652 | This is allowed only in the value cell of a symbol, | 2645 | This is allowed only in the value cell of a symbol, |
| @@ -5023,26 +5016,6 @@ maybe_gc (void) | |||
| 5023 | garbage_collect (); | 5016 | garbage_collect (); |
| 5024 | } | 5017 | } |
| 5025 | 5018 | ||
| 5026 | INLINE intmax_t | ||
| 5027 | ranged_integer_to_int (Lisp_Object num, intmax_t min, intmax_t max) | ||
| 5028 | { | ||
| 5029 | CHECK_INTEGER (num); | ||
| 5030 | intmax_t result; | ||
| 5031 | if (!(integer_to_intmax (num, &result) && min <= result && result <= max)) | ||
| 5032 | args_out_of_range_3 (num, make_int (min), make_int (max)); | ||
| 5033 | return result; | ||
| 5034 | } | ||
| 5035 | |||
| 5036 | INLINE uintmax_t | ||
| 5037 | ranged_integer_to_uint (Lisp_Object num, uintmax_t max) | ||
| 5038 | { | ||
| 5039 | CHECK_INTEGER (num); | ||
| 5040 | uintmax_t result; | ||
| 5041 | if (!(integer_to_uintmax (num, &result) && result <= max)) | ||
| 5042 | args_out_of_range_3 (num, make_fixed_natnum (0), make_uint (max)); | ||
| 5043 | return result; | ||
| 5044 | } | ||
| 5045 | |||
| 5046 | INLINE_HEADER_END | 5019 | INLINE_HEADER_END |
| 5047 | 5020 | ||
| 5048 | #endif /* EMACS_LISP_H */ | 5021 | #endif /* EMACS_LISP_H */ |