Subject: bug#15778: 24.3; cperl-mode causes emacs to lock up

From: Eli Zaretskii <[email-masked]>
Date: Fri, 01 Nov 2013 18:26:14 +0200

> From: Nathan Trapuzzano <[email-masked]>
> Cc: [email-masked]
> Date: Fri, 01 Nov 2013 10:59:12 -0400
> 
> emacs -Q
> M-: (defalias 'perl-mode 'cperl-mode)
> C-x C-f Beta.pm
> M-x goto-line 44
> C-k

It loops here:

    (while (and beg
		(progn
		  (beginning-of-line)
		  (eq (get-text-property (setq beg (point)) 'syntax-type)
		      'multiline)))
      (if (setq beg (cperl-beginning-of-property beg 'syntax-type))
	  (goto-char beg)))

This happens because cperl-beginning-of-property does this:

  (or (previous-single-property-change (cperl-1+ p) prop lim)
      (point-min))

So it starts its search backwards for the beginning of the property
from the position 1 _after_ BEG.  In this case,
previous-single-property-change returns BEG, so the code stays at BEG,
and thus loops indefinitely.

Looks like a bug in cperl-mode, as I don't see any protection in this
loop against such a calamity.  Is it safe to assume that a
'syntax-type' property will never cover exactly one buffer position?

(I have no idea why the defalias is needed to trigger the bug.)