Subject: Re: bug#34186: 26.1; locking up
From: Alan Mackenzie <[email-masked]>
To: Eli Zaretskii <[email-masked]>, Michael Menefee <[email-masked]>
Cc: [email-masked]
Date: Fri, 25 Jan 2019 16:30:07 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello, Eli and Michael.

On Thu, Jan 24, 2019 at 19:41:21 +0200, Eli Zaretskii wrote:
> > From: Michael Menefee <[email-masked]>
> > Date: Thu, 24 Jan 2019 10:32:34 -0600
> > Cc: [email-masked]

> > I have found the minimum necessary to consistently reproduce.  copy/paste this into something.c to see if you
> > get same results:

> > void *AVL_first(AVL_t *);
> > void *AVL_last(AVL_t *);
> > #define (<--- locks up with pressing open parenthesis

> Thanks, now I can reproduce this.  Alan, please take a look.

I've committed the following fix to the emacs-26 branch.  I'm closing
the bug.

@Michael: This patch should apply cleanly to your Emacs 26.1 version (in
directory .../emacs/lisp/progmodes).  If you apply it, please
byte-compile the file before using it.  (If you want any help with the
patching and/or byte-compiling, feel free to send me private email.)

commit 9078f34e84178553cd59bc03ac1b58cb56038436
Author: Alan Mackenzie <[email-masked]>
Date:   Fri Jan 25 16:14:00 2019 +0000

    Fix a loop in c-fl-decl-start.  This fixes bug #34186.
    
    * lisp/progmodes/cc-mode.el (c-fl-decl-start) In the pair of operations
    c-syntactic-skip-backward and c-forward-syntactic-ws, ensure the latter
    doesn't come back to the position before the former, and break out of the
    enclosing loop if it does.

diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 8cbb4e8612..5283cfea6e 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -1487,6 +1487,7 @@ c-fl-decl-start
   ;; lock context (etc.) fontification.
   (goto-char pos)
   (let ((lit-start (c-literal-start))
+	old-pos
 	(new-pos pos)
 	capture-opener
 	bod-lim bo-decl)
@@ -1509,12 +1510,14 @@ c-fl-decl-start
     (while
 	;; Go to a less nested declaration each time round this loop.
 	(and
+	 (setq old-pos (point))
 	 (c-syntactic-skip-backward "^;{}" bod-lim t)
 	 (> (point) bod-lim)
 	 (progn (c-forward-syntactic-ws)
 		;; Have we got stuck in a comment at EOB?
 		(not (and (eobp)
 			  (c-literal-start))))
+	 (< (point) old-pos)
 	 (progn (setq bo-decl (point))
 		(or (not (looking-at c-protection-key))
 		    (c-forward-keyword-clause 1)))

-- 
Alan Mackenzie (Nuremberg, Germany).