Subject: bug#40000: 27.0.60; next-single-char-property-change hangs on bad argument

From: Federico Tedin <[email-masked]>
Date: Mon, 13 Apr 2020 15:52:17 +0200

(congratulations on bug #40000! :-)

I'm attaching a patch which solves the issue. Now, all the
`next-*-property-change' functions return LIMIT when it has been
specified and no properties where found up to the buffer's end.

On the other hand, the `previous-*-property-change' functions are a bit
inconsistent for negative values of LIMIT:

(previous-single-char-property-change 2 'test nil -1) -> `args-out-of-range' 
(previous-single-property-change      2 'test nil -1) -> -1
(previous-char-property-change        2           -1) ->  1
(previous-property-change             2       nil -1) -> -1

For positive values of LIMIT I didn't find any problems. Although a
negative value for LIMIT doesn't make any sense, only the documentation
for `previous-char-property-change' mentions that "LIMIT is a no-op if
it is less than (point-min)". So maybe this behavior could be added to
the other 3 functions as well.

>From 3d82dbc65c26d64f4dbef87e4dd3355eaf093ec0 Mon Sep 17 00:00:00 2001
From: Federico Tedin <[email-masked]>
Date: Mon, 13 Apr 2020 15:30:58 +0200
Subject: [PATCH] Prevent hanging in next-single-char-property-change

* src/textprop.c (Fnext_single_char_property_change): Prevent Emacs
from hanging when the value of LIMIT is greater than the buffer's end
position. (Bug#40000)
---
 src/textprop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/textprop.c b/src/textprop.c
index 960dba3f8d..146cb2c76b 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -823,7 +823,7 @@ DEFUN ("next-single-char-property-change", Fnext_single_char_property_change,
 	while (true)
 	  {
 	    position = Fnext_char_property_change (position, limit);
-	    if (XFIXNAT (position) >= XFIXNAT (limit))
+	    if (XFIXNAT (position) >= XFIXNAT (limit) || XFIXNAT (position) >= ZV)
 	      {
 		position = limit;
 		break;
-- 
2.17.1