aboutsummaryrefslogtreecommitdiffstats
path: root/src/charset.c
diff options
context:
space:
mode:
authorPaul Eggert2011-06-06 01:29:01 -0700
committerPaul Eggert2011-06-06 01:29:01 -0700
commitbe44ca6cd47bff4cb0dfcfd71aa14f10fdab5434 (patch)
tree34110ed6783c1314604f3382e8cd6d0812b939e3 /src/charset.c
parentd1f3d2afe1057a99b9dec6d1bd5b57bfee81fdff (diff)
downloademacs-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/charset.c')
-rw-r--r--src/charset.c38
1 files changed, 4 insertions, 34 deletions
diff --git a/src/charset.c b/src/charset.c
index bfebe02f52e..770e98c99e1 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -932,17 +932,8 @@ usage: (define-charset-internal ...) */)
932 val = args[charset_arg_min_code]; 932 val = args[charset_arg_min_code];
933 if (! NILP (val)) 933 if (! NILP (val))
934 { 934 {
935 unsigned code; 935 unsigned code = cons_to_unsigned (val, UINT_MAX);
936 936
937 if (INTEGERP (val))
938 code = XINT (val);
939 else
940 {
941 CHECK_CONS (val);
942 CHECK_NUMBER_CAR (val);
943 CHECK_NUMBER_CDR (val);
944 code = (XINT (XCAR (val)) << 16) | (XINT (XCDR (val)));
945 }
946 if (code < charset.min_code 937 if (code < charset.min_code
947 || code > charset.max_code) 938 || code > charset.max_code)
948 args_out_of_range_3 (make_number (charset.min_code), 939 args_out_of_range_3 (make_number (charset.min_code),
@@ -954,17 +945,8 @@ usage: (define-charset-internal ...) */)
954 val = args[charset_arg_max_code]; 945 val = args[charset_arg_max_code];
955 if (! NILP (val)) 946 if (! NILP (val))
956 { 947 {
957 unsigned code; 948 unsigned code = cons_to_unsigned (val, UINT_MAX);
958 949
959 if (INTEGERP (val))
960 code = XINT (val);
961 else
962 {
963 CHECK_CONS (val);
964 CHECK_NUMBER_CAR (val);
965 CHECK_NUMBER_CDR (val);
966 code = (XINT (XCAR (val)) << 16) | (XINT (XCDR (val)));
967 }
968 if (code < charset.min_code 950 if (code < charset.min_code
969 || code > charset.max_code) 951 || code > charset.max_code)
970 args_out_of_range_3 (make_number (charset.min_code), 952 args_out_of_range_3 (make_number (charset.min_code),
@@ -1865,17 +1847,7 @@ and CODE-POINT to a character. Currently not supported and just ignored. */)
1865 struct charset *charsetp; 1847 struct charset *charsetp;
1866 1848
1867 CHECK_CHARSET_GET_ID (charset, id); 1849 CHECK_CHARSET_GET_ID (charset, id);
1868 if (CONSP (code_point)) 1850 code = cons_to_unsigned (code_point, UINT_MAX);
1869 {
1870 CHECK_NATNUM_CAR (code_point);
1871 CHECK_NATNUM_CDR (code_point);
1872 code = (XINT (XCAR (code_point)) << 16) | (XINT (XCDR (code_point)));
1873 }
1874 else
1875 {
1876 CHECK_NATNUM (code_point);
1877 code = XINT (code_point);
1878 }
1879 charsetp = CHARSET_FROM_ID (id); 1851 charsetp = CHARSET_FROM_ID (id);
1880 c = DECODE_CHAR (charsetp, code); 1852 c = DECODE_CHAR (charsetp, code);
1881 return (c >= 0 ? make_number (c) : Qnil); 1853 return (c >= 0 ? make_number (c) : Qnil);
@@ -1900,9 +1872,7 @@ code-point in CCS. Currently not supported and just ignored. */)
1900 code = ENCODE_CHAR (charsetp, XINT (ch)); 1872 code = ENCODE_CHAR (charsetp, XINT (ch));
1901 if (code == CHARSET_INVALID_CODE (charsetp)) 1873 if (code == CHARSET_INVALID_CODE (charsetp))
1902 return Qnil; 1874 return Qnil;
1903 if (code > 0x7FFFFFF) 1875 return INTEGER_TO_CONS (code);
1904 return Fcons (make_number (code >> 16), make_number (code & 0xFFFF));
1905 return make_number (code);
1906} 1876}
1907 1877
1908 1878