summaryrefslogtreecommitdiff
path: root/src/textprop.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2019-06-27 12:31:27 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2019-06-27 12:35:08 -0700
commit4893a09c005cac81c05cd3db05c87225be6a7b42 (patch)
tree1e1e193f61c97067076a1b2f0940c79d5e92ed33 /src/textprop.c
parent3502d4c1b587057c2f5907997f74ae0a2e0d2a7d (diff)
downloademacs-4893a09c005cac81c05cd3db05c87225be6a7b42.tar.gz
Clean up use of XFIXNUM etc.
A few bits of the code were relying on the fact that XFIXNUM, XFIXNAT, and XUFIXNUM do something even with arguments that are not fixnums/fixnats. Separate these rare uses out into XFIXNUM_RAW and XUFIXNUM_RAW. Problem and original patch reported by Pip Cet (Bug#36370). * src/ccl.c (Fccl_execute_on_string): * src/fileio.c (Finsert_file_contents, a_write) (Fdo_auto_save): * src/process.c (conv_lisp_to_sockaddr): * src/textprop.c (Fnext_single_char_property_change) (Fprevious_single_char_property_change) (Fnext_property_change, Fnext_single_property_change) (Fprevious_property_change) (Fprevious_single_property_change): Don’t assume fixnums are nonnegative. * src/ccl.c (Fccl_execute_on_string): Fix range-checking bug if AREF (status, i) is out of int range. * src/data.c (arith_driver): Use XFIXNUM_RAW as we want efficient garbage if the value is not a fixnum. * src/dosfns.c (Fint86, Fdos_memput): Check that args are nonnegative. * src/image.c (lookup_image): Check that args are in range. * src/lisp.h (lisp_h_XHASH): Use XUFIXNUM_RAW, since this is for hashing. (lisp_h_XFIXNAT, XFIXNAT) [USE_LSB_TAG]: Remove macros. (lisp_h_XFIXNUM_RAW, XFIXNUM_RAW) [USE_LSB_TAG]: New macros, with the semantics of the old macros without _RAW. (XFIXNUM_RAW, XUFIXNUM_RAW): New inline functions, with the semantics of the old functions without _RAW. (FIXNUMP): Move definition up to avoid forward use. (XFIXNUM, XFIXNAT, XUFIXNUM): Use eassume to add a runtime check (when debugging) that the argument has the proper form. (XFIXNUM, XFIXNAT): Now inline functions only, since they refer to their arguments more than once now that they use eassume. * src/textprop.c (Fprevious_single_char_property_change): Avoid fixnum overflow with invalid input. (set_text_properties): Fix unlikely failure to validate arguments, by using EQ instead of XFIXNAT. * src/w32term.c (w32_draw_glyph_string): * src/xterm.c (x_draw_glyph_string): Treat negative minimums as 0 rather than as garbage patterns.
Diffstat (limited to 'src/textprop.c')
-rw-r--r--src/textprop.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/textprop.c b/src/textprop.c
index ae42c44185f..3026ec7e992 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -799,7 +799,7 @@ last valid position in OBJECT. */)
else
CHECK_FIXNUM_COERCE_MARKER (limit);
- if (XFIXNAT (position) >= XFIXNAT (limit))
+ if (XFIXNAT (position) >= XFIXNUM (limit))
{
position = limit;
if (XFIXNAT (position) > ZV)
@@ -881,16 +881,17 @@ first valid position in OBJECT. */)
else
CHECK_FIXNUM_COERCE_MARKER (limit);
- if (XFIXNAT (position) <= XFIXNAT (limit))
+ if (XFIXNUM (position) <= XFIXNUM (limit))
{
position = limit;
- if (XFIXNAT (position) < BEGV)
+ if (XFIXNUM (position) < BEGV)
XSETFASTINT (position, BEGV);
}
else
{
Lisp_Object initial_value
- = Fget_char_property (make_fixnum (XFIXNAT (position) - 1),
+ = Fget_char_property (make_fixnum (XFIXNUM (position)
+ - (0 <= XFIXNUM (position))),
prop, object);
while (true)
@@ -970,13 +971,13 @@ past position LIMIT; return LIMIT if nothing is found before LIMIT. */)
next = next_interval (i);
while (next && intervals_equal (i, next)
- && (NILP (limit) || next->position < XFIXNAT (limit)))
+ && (NILP (limit) || next->position < XFIXNUM (limit)))
next = next_interval (next);
if (!next
|| (next->position
>= (FIXNUMP (limit)
- ? XFIXNAT (limit)
+ ? XFIXNUM (limit)
: (STRINGP (object)
? SCHARS (object)
: BUF_ZV (XBUFFER (object))))))
@@ -1019,13 +1020,13 @@ past position LIMIT; return LIMIT if nothing is found before LIMIT. */)
next = next_interval (i);
while (next
&& EQ (here_val, textget (next->plist, prop))
- && (NILP (limit) || next->position < XFIXNAT (limit)))
+ && (NILP (limit) || next->position < XFIXNUM (limit)))
next = next_interval (next);
if (!next
|| (next->position
>= (FIXNUMP (limit)
- ? XFIXNAT (limit)
+ ? XFIXNUM (limit)
: (STRINGP (object)
? SCHARS (object)
: BUF_ZV (XBUFFER (object))))))
@@ -1069,13 +1070,13 @@ back past position LIMIT; return LIMIT if nothing is found until LIMIT. */)
previous = previous_interval (i);
while (previous && intervals_equal (previous, i)
&& (NILP (limit)
- || (previous->position + LENGTH (previous) > XFIXNAT (limit))))
+ || (previous->position + LENGTH (previous) > XFIXNUM (limit))))
previous = previous_interval (previous);
if (!previous
|| (previous->position + LENGTH (previous)
<= (FIXNUMP (limit)
- ? XFIXNAT (limit)
+ ? XFIXNUM (limit)
: (STRINGP (object) ? 0 : BUF_BEGV (XBUFFER (object))))))
return limit;
else
@@ -1122,13 +1123,13 @@ back past position LIMIT; return LIMIT if nothing is found until LIMIT. */)
while (previous
&& EQ (here_val, textget (previous->plist, prop))
&& (NILP (limit)
- || (previous->position + LENGTH (previous) > XFIXNAT (limit))))
+ || (previous->position + LENGTH (previous) > XFIXNUM (limit))))
previous = previous_interval (previous);
if (!previous
|| (previous->position + LENGTH (previous)
<= (FIXNUMP (limit)
- ? XFIXNAT (limit)
+ ? XFIXNUM (limit)
: (STRINGP (object) ? 0 : BUF_BEGV (XBUFFER (object))))))
return limit;
else
@@ -1353,8 +1354,8 @@ set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties,
/* If we want no properties for a whole string,
get rid of its intervals. */
if (NILP (properties) && STRINGP (object)
- && XFIXNAT (start) == 0
- && XFIXNAT (end) == SCHARS (object))
+ && EQ (start, make_fixnum (0))
+ && EQ (end, make_fixnum (SCHARS (object))))
{
if (!string_intervals (object))
return Qnil;