diff options
| author | Paul Eggert | 2011-06-06 01:29:01 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-06-06 01:29:01 -0700 |
| commit | be44ca6cd47bff4cb0dfcfd71aa14f10fdab5434 (patch) | |
| tree | 34110ed6783c1314604f3382e8cd6d0812b939e3 /src/lisp.h | |
| parent | d1f3d2afe1057a99b9dec6d1bd5b57bfee81fdff (diff) | |
| download | emacs-be44ca6cd47bff4cb0dfcfd71aa14f10fdab5434.tar.gz emacs-be44ca6cd47bff4cb0dfcfd71aa14f10fdab5434.zip | |
Check for overflow when converting integer to cons and back.
* charset.c (Fdefine_charset_internal, Fdecode_char):
Use cons_to_unsigned to catch overflow.
(Fencode_char): Use INTEGER_TO_CONS.
* composite.h (LGLYPH_CODE): Use cons_to_unsigned.
(LGLYPH_SET_CODE): Use INTEGER_TO_CONS.
* data.c (long_to_cons, cons_to_long): Remove.
(cons_to_unsigned, cons_to_signed): New functions.
These signal an error for invalid or out-of-range values.
* dired.c (Ffile_attributes): Use INTEGER_TO_CONS.
* fileio.c (Fset_visited_file_modtime): Use CONS_TO_INTEGER.
* font.c (Ffont_variation_glyphs):
* fontset.c (Finternal_char_font): Use INTEGER_TO_CONS.
* lisp.h: Include <intprops.h>.
(INTEGER_TO_CONS, CONS_TO_INTEGER): New macros.
(cons_to_signed, cons_to_unsigned): New decls.
(long_to_cons, cons_to_long): Remove decls.
* undo.c (record_first_change): Use INTEGER_TO_CONS.
(Fprimitive_undo): Use CONS_TO_INTEGER.
* xfns.c (Fx_window_property): Likewise.
* xselect.c: Include <limits.h>.
(x_own_selection, selection_data_to_lisp_data):
Use INTEGER_TO_CONS.
(x_handle_selection_request, x_handle_selection_clear)
(x_get_foreign_selection, Fx_disown_selection_internal)
(Fx_get_atom_name, x_send_client_event): Use CONS_TO_INTEGER.
(lisp_data_to_selection_data): Use cons_to_unsigned.
(x_fill_property_data): Use cons_to_signed.
Report values out of range.
Diffstat (limited to 'src/lisp.h')
| -rw-r--r-- | src/lisp.h | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/lisp.h b/src/lisp.h index a46436e718b..1c1e3ec3708 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -24,6 +24,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 24 | #include <stddef.h> | 24 | #include <stddef.h> |
| 25 | #include <inttypes.h> | 25 | #include <inttypes.h> |
| 26 | 26 | ||
| 27 | #include <intprops.h> | ||
| 28 | |||
| 27 | /* Use the configure flag --enable-checking[=LIST] to enable various | 29 | /* Use the configure flag --enable-checking[=LIST] to enable various |
| 28 | types of run time checks for Lisp objects. */ | 30 | types of run time checks for Lisp objects. */ |
| 29 | 31 | ||
| @@ -2408,9 +2410,35 @@ EXFUN (Fadd1, 1); | |||
| 2408 | EXFUN (Fsub1, 1); | 2410 | EXFUN (Fsub1, 1); |
| 2409 | EXFUN (Fmake_variable_buffer_local, 1); | 2411 | EXFUN (Fmake_variable_buffer_local, 1); |
| 2410 | 2412 | ||
| 2413 | /* Convert the integer I to an Emacs representation, either the integer | ||
| 2414 | itself, or a cons of two or three integers, or if all else fails a float. | ||
| 2415 | I should not have side effects. */ | ||
| 2416 | #define INTEGER_TO_CONS(i) \ | ||
| 2417 | (! FIXNUM_OVERFLOW_P (i) \ | ||
| 2418 | ? make_number (i) \ | ||
| 2419 | : ! ((FIXNUM_OVERFLOW_P (INTMAX_MIN >> 16) \ | ||
| 2420 | || FIXNUM_OVERFLOW_P (UINTMAX_MAX >> 16)) \ | ||
| 2421 | && FIXNUM_OVERFLOW_P ((i) >> 16)) \ | ||
| 2422 | ? Fcons (make_number ((i) >> 16), make_number ((i) & 0xffff)) \ | ||
| 2423 | : ! ((FIXNUM_OVERFLOW_P (INTMAX_MIN >> 16 >> 24) \ | ||
| 2424 | || FIXNUM_OVERFLOW_P (UINTMAX_MAX >> 16 >> 24)) \ | ||
| 2425 | && FIXNUM_OVERFLOW_P ((i) >> 16 >> 24)) \ | ||
| 2426 | ? Fcons (make_number ((i) >> 16 >> 24), \ | ||
| 2427 | Fcons (make_number ((i) >> 16 & 0xffffff), \ | ||
| 2428 | make_number ((i) & 0xffff))) \ | ||
| 2429 | : make_float (i)) | ||
| 2430 | |||
| 2431 | /* Convert the Emacs representation CONS back to an integer of type | ||
| 2432 | TYPE, storing the result the variable VAR. Signal an error if CONS | ||
| 2433 | is not a valid representation or is out of range for TYPE. */ | ||
| 2434 | #define CONS_TO_INTEGER(cons, type, var) \ | ||
| 2435 | (TYPE_SIGNED (type) \ | ||
| 2436 | ? ((var) = cons_to_signed (cons, TYPE_MINIMUM (type), TYPE_MAXIMUM (type))) \ | ||
| 2437 | : ((var) = cons_to_unsigned (cons, TYPE_MAXIMUM (type)))) | ||
| 2438 | extern intmax_t cons_to_signed (Lisp_Object, intmax_t, intmax_t); | ||
| 2439 | extern uintmax_t cons_to_unsigned (Lisp_Object, uintmax_t); | ||
| 2440 | |||
| 2411 | extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *); | 2441 | extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *); |
| 2412 | extern Lisp_Object long_to_cons (unsigned long); | ||
| 2413 | extern unsigned long cons_to_long (Lisp_Object); | ||
| 2414 | extern void args_out_of_range (Lisp_Object, Lisp_Object) NO_RETURN; | 2442 | extern void args_out_of_range (Lisp_Object, Lisp_Object) NO_RETURN; |
| 2415 | extern void args_out_of_range_3 (Lisp_Object, Lisp_Object, | 2443 | extern void args_out_of_range_3 (Lisp_Object, Lisp_Object, |
| 2416 | Lisp_Object) NO_RETURN; | 2444 | Lisp_Object) NO_RETURN; |