From 85cc6738ed6d07b13ad749de80e47170a1df0d7a Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Sun, 14 May 2006 21:55:34 +0000 Subject: [PATCH] (Fnext_single_char_property_change) (Fprevious_single_char_property_change): Don't allow returning value beyond LIMIT in any cases. (Fnext_char_property_change, Fprevious_char_property_change): Doc fix. --- src/textprop.c | 68 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/src/textprop.c b/src/textprop.c index e2f9c531735..87fa6742919 100644 --- a/src/textprop.c +++ b/src/textprop.c @@ -717,10 +717,11 @@ DEFUN ("next-char-property-change", Fnext_char_property_change, This scans characters forward in the current buffer from POSITION till it finds a change in some text property, or the beginning or end of an overlay, and returns the position of that. -If none is found, the function returns (point-max). +If none is found up to (point-max), the function returns (point-max). If the optional second argument LIMIT is non-nil, don't search -past position LIMIT; return LIMIT if nothing is found before LIMIT. */) +past position LIMIT; return LIMIT if nothing is found before LIMIT. +LIMIT is a no-op if it is greater than (point-max). */) (position, limit) Lisp_Object position, limit; { @@ -742,10 +743,11 @@ DEFUN ("previous-char-property-change", Fprevious_char_property_change, Scans characters backward in the current buffer from POSITION till it finds a change in some text property, or the beginning or end of an overlay, and returns the position of that. -If none is found, the function returns (point-max). +If none is found since (point-min), the function returns (point-min). If the optional second argument LIMIT is non-nil, don't search -past position LIMIT; return LIMIT if nothing is found before LIMIT. */) +past position LIMIT; return LIMIT if nothing is found before LIMIT. +LIMIT is a no-op if it is less than (point-min). */) (position, limit) Lisp_Object position, limit; { @@ -771,6 +773,9 @@ If the optional third argument OBJECT is a buffer (or nil, which means the current buffer), POSITION is a buffer position (integer or marker). If OBJECT is a string, POSITION is a 0-based index into it. +In a string, scan runs to the end of the string. +In a buffer, it runs to (point-max), and the value cannot exceed that. + The property values are compared with `eq'. If the property is constant all the way to the end of OBJECT, return the last valid position in OBJECT. @@ -812,22 +817,30 @@ past position LIMIT; return LIMIT if nothing is found before LIMIT. */) initial_value = Fget_char_property (position, prop, object); if (NILP (limit)) - XSETFASTINT (limit, BUF_ZV (current_buffer)); + XSETFASTINT (limit, ZV); else CHECK_NUMBER_COERCE_MARKER (limit); - for (;;) + if (XFASTINT (position) >= XFASTINT (limit)) { - position = Fnext_char_property_change (position, limit); - if (XFASTINT (position) >= XFASTINT (limit)) { - position = limit; - break; - } - - value = Fget_char_property (position, prop, object); - if (!EQ (value, initial_value)) - break; + position = limit; + if (XFASTINT (position) > ZV) + XSETFASTINT (position, ZV); } + else + while (1) + { + position = Fnext_char_property_change (position, limit); + if (XFASTINT (position) >= XFASTINT (limit)) + { + position = limit; + break; + } + + value = Fget_char_property (position, prop, object); + if (!EQ (value, initial_value)) + break; + } unbind_to (count, Qnil); } @@ -845,6 +858,9 @@ If the optional third argument OBJECT is a buffer (or nil, which means the current buffer), POSITION is a buffer position (integer or marker). If OBJECT is a string, POSITION is a 0-based index into it. +In a string, scan runs to the start of the string. +In a buffer, it runs to (point-min), and the value cannot be less than that. + The property values are compared with `eq'. If the property is constant all the way to the start of OBJECT, return the first valid position in OBJECT. @@ -883,19 +899,23 @@ back past position LIMIT; return LIMIT if nothing is found before LIMIT. */) CHECK_NUMBER_COERCE_MARKER (position); if (NILP (limit)) - XSETFASTINT (limit, BUF_BEGV (current_buffer)); + XSETFASTINT (limit, BEGV); else CHECK_NUMBER_COERCE_MARKER (limit); if (XFASTINT (position) <= XFASTINT (limit)) - position = limit; + { + position = limit; + if (XFASTINT (position) < BEGV) + XSETFASTINT (position, BEGV); + } else { - Lisp_Object initial_value = - Fget_char_property (make_number (XFASTINT (position) - 1), - prop, object); + Lisp_Object initial_value + = Fget_char_property (make_number (XFASTINT (position) - 1), + prop, object); - for (;;) + while (1) { position = Fprevious_char_property_change (position, limit); @@ -906,9 +926,9 @@ back past position LIMIT; return LIMIT if nothing is found before LIMIT. */) } else { - Lisp_Object value = - Fget_char_property (make_number (XFASTINT (position) - 1), - prop, object); + Lisp_Object value + = Fget_char_property (make_number (XFASTINT (position) - 1), + prop, object); if (!EQ (value, initial_value)) break; -- 2.39.5