[gnu.emacs.bug] infinite loop in c-backward-to-start-of-if

jbw%bucsf.BU.EDU@BU-IT.BU.EDU (Joe Wells) (01/21/89)

In a recent article, someone complains about an infinite loop:

>  c indentation hangs after a recover file
>  
>  I run gnuemacs and do a recover-file on channel.h.
>  It asks if I am sure, I say yes.
>  I go to the 4th line of the file and press tab.
>  gnuemacs does nothing, until I hit ^G.
>  
>  here is a more readible version of #channel.h#
>  #define BI_CHANNEL_1_TO(D,P) \
>  if ((D) == 1.0)
>     *(P) = ('\001')
>     else
>  *(P) = ('/000");

This has nothing to do with recover-file.  It is the contents of the
file.  The bug is in c-backward-to-start-of-if.  This functions counts
"else" and "if" tokens to find the "if" matching this "else".
However, the "if" in the example is missed because backward-sexp skips
over it.  This happens because the "if" follows a backslash and
newline character.  Then c-backward-to-start-of-if loops at the
beginning of the buffer.  Here is a fix:

###start of diff###
*** dist-18.52/lisp/c-mode.el	Fri May 27 20:28:12 1988
--- c-mode.el.new	Fri Jan 20 22:36:14 1989
***************
*** 524,530 ****
  	     (setq if-level (1+ if-level)))
  	    ((looking-at "if\\b")
  	     (setq if-level (1- if-level)))
! 	    ((< (point) limit)
  	     (setq if-level 0)
  	     (goto-char limit))))))
  
--- 524,530 ----
  	     (setq if-level (1+ if-level)))
  	    ((looking-at "if\\b")
  	     (setq if-level (1- if-level)))
! 	    ((<= (point) limit)
  	     (setq if-level 0)
  	     (goto-char limit))))))
  
###end of diff###

--
Joe Wells		INTERNET: jbw%bucsf.bu.edu@bu-it.bu.edu
UUCP: ...!harvard!bu-cs!bucsf!jbw	      IP: [128.197.2.9]