Subject: bug#21205: Error during redisplay: (jit-lock-function 3491)

From: Alan Mackenzie <[email-masked]>
Date: Fri, 7 Aug 2015 20:52:55 +0000

Hello, Eli and Netjune.

On Fri, Aug 07, 2015 at 03:54:10PM +0300, Eli Zaretskii wrote:
> > From: 张海君 <[email-masked]>
> > Date: Fri, 07 Aug 2015 18:43:54 +0800

> > Run emacs with "emacs -Q", and then eval the following code:
> > ------------------------------------------------------------
> > (setq font-lock-maximum-decoration 2
> > 	  jit-lock-defer-time 0.05)
> > (setq-default show-trailing-whitespace t)
> > ------------------------------------------------------------

> > Then open the attached c file, and scroll down the buffer with key C-v C-v ... until the end of buffer.
> > Switch to the message buffer *Message*. There are some error message as the following:
> > ------------------------------------------------------------------------------
> > Error during redisplay: (jit-lock-function 3102) signaled (error "Invalid search bound (wrong side of point)")

> The errors are triggered by c-syntactic-re-search-forward.  Here's the
> backtrace from the first such error, with the current master:

[ .... ]

>   Lisp Backtrace:
>   "re-search-forward" (0x825430)
>   "c-syntactic-re-search-forward" (0x8259f0)
>   "c-font-lock-declarators" (0x825fd0)
>   0x1c9cda0 PVEC_COMPILED
>   "font-lock-fontify-keywords-region" (0x826b30)
>   "font-lock-default-fontify-region" (0x8270d0)
>   "c-font-lock-fontify-region" (0x827680)
>   "font-lock-fontify-region" (0x827c28)

[ .... ]

Thanks for that, Eli!  It made it fairly easy to track down the bug,
which was simply failing to check if point had advanced too far at one
critical place in c-font-lock-declarators.

Netjune: would you please try out the following patch (it should apply
cleanly to the cc-fonts.el in ..../emacs-24.5/lisp/progmodes/), and
confirm that the bug has been fixed, or tell me what is still causing
problems.

diff -r 88b4140d56af cc-fonts.el
--- a/cc-fonts.el	Tue May 12 10:03:55 2015 +0000
+++ b/cc-fonts.el	Fri Aug 07 20:41:38 2015 +0000
@@ -1141,6 +1141,7 @@
 			     (looking-at "{"))
 			(c-safe (c-forward-sexp) t) ; over { .... }
 		      t)
+		    (< (point) limit)
 		    ;; FIXME: Should look for c-decl-end markers here;
 		    ;; we might go far into the following declarations
 		    ;; in e.g. ObjC mode (see e.g. methods-4.m).

Thanks for the bug report!

-- 
Alan Mackenzie (Nuremberg, Germany).