unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#1982: 23.0.60; Infinite loop in align-regexp
@ 2009-01-21 23:30 ` Geoff Gole
  2009-01-24 23:50   ` bug#1982: marked as done (23.0.60; Infinite loop in align-regexp) Emacs bug Tracking System
  0 siblings, 1 reply; 2+ messages in thread
From: Geoff Gole @ 2009-01-21 23:30 UTC (permalink / raw)
  To: emacs-pretest-bug

[-- Attachment #1: Type: text/plain, Size: 2136 bytes --]

This was originally sent to emacs-devel. Since it's been a week with
no response I'm going to assume that that was the wrong place, thus
I'm copying it here. My apologies if the duplication is inappropriate.

For certain choices of regexp and region text, align-regexp will enter
an infinite loop. To reproduce:

  emacs -Q
  RET foo
  C-SPC C-a
  M-x align-regexp
  \<

Note that the infinite loop won't occur for text at the beginning of
the buffer, so make sure to test at least one newline down.

I'm suprised that this hasn't come up before. I would have thought
aligning to beginning-of-word would be a common case. Anyway, the
problem seems to be that align-region assumes that a successful search
will always move point forward. The following patch attempts to fix
this:

--- /home/ggole/src/emacs/lisp/align.el	2009-01-05 12:18:39.000000000 +0900
+++ loopfix-align.el	2009-01-22 08:15:59.000000000 +0900
@@ -1307,6 +1307,7 @@
 		 (rulesep (assq 'separate rule))
 		 (thissep (if rulesep (cdr rulesep) separate))
 		 same (eol 0)
+		 search-origin
 		 group group-c
 		 spacing spacing-c
 		 tab-stop tab-stop-c
@@ -1412,6 +1413,7 @@
 		      ;; while we can find the rule in the alignment
 		      ;; region..
 		      (while (and (< (point) end-mark)
+				  (setq search-origin (point))
 				  (if regfunc
 				      (funcall regfunc end-mark nil)
 				    (re-search-forward regexp
@@ -1436,7 +1438,8 @@
 			;; if the search ended us on the beginning of
 			;; the next line, move back to the end of the
 			;; previous line.
-			(if (bolp)
+			(if (and (bolp)
+				 (> (point) search-origin))
 			    (forward-char -1))

 			;; lookup the `group' attribute the first time
@@ -1576,7 +1579,12 @@
 			    ;; the next line; don't bother searching
 			    ;; anymore on this one
 			    (if (and (not repeat) (not (bolp)))
-				(forward-line)))))
+				(forward-line))
+
+			    ;; if the search did not change point,
+			    ;; move forward to avoid an infinite loop
+			    (if (= (point) search-origin)
+				(forward-char)))))

 		      ;; when they are no more matches for this rule,
 		      ;; align whatever was left over

[-- Attachment #2: align-regexp-loopfix.diff --]
[-- Type: text/x-patch, Size: 1358 bytes --]

--- /home/ggole/src/emacs/lisp/align.el	2009-01-05 12:18:39.000000000 +0900
+++ loopfix-align.el	2009-01-22 08:15:59.000000000 +0900
@@ -1307,6 +1307,7 @@
 		 (rulesep (assq 'separate rule))
 		 (thissep (if rulesep (cdr rulesep) separate))
 		 same (eol 0)
+		 search-origin
 		 group group-c
 		 spacing spacing-c
 		 tab-stop tab-stop-c
@@ -1412,6 +1413,7 @@
 		      ;; while we can find the rule in the alignment
 		      ;; region..
 		      (while (and (< (point) end-mark)
+				  (setq search-origin (point))
 				  (if regfunc
 				      (funcall regfunc end-mark nil)
 				    (re-search-forward regexp
@@ -1436,7 +1438,8 @@
 			;; if the search ended us on the beginning of
 			;; the next line, move back to the end of the
 			;; previous line.
-			(if (bolp)
+			(if (and (bolp)
+				 (> (point) search-origin))
 			    (forward-char -1))
 
 			;; lookup the `group' attribute the first time
@@ -1576,7 +1579,12 @@
 			    ;; the next line; don't bother searching
 			    ;; anymore on this one
 			    (if (and (not repeat) (not (bolp)))
-				(forward-line)))))
+				(forward-line))
+
+			    ;; if the search did not change point,
+			    ;; move forward to avoid an infinite loop
+			    (if (= (point) search-origin)
+				(forward-char)))))
 
 		      ;; when they are no more matches for this rule,
 		      ;; align whatever was left over

^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#1982: marked as done (23.0.60; Infinite loop in align-regexp)
  2009-01-21 23:30 ` bug#1982: 23.0.60; Infinite loop in align-regexp Geoff Gole
@ 2009-01-24 23:50   ` Emacs bug Tracking System
  0 siblings, 0 replies; 2+ messages in thread
From: Emacs bug Tracking System @ 2009-01-24 23:50 UTC (permalink / raw)
  To: Chong Yidong

[-- Attachment #1: Type: text/plain, Size: 862 bytes --]


Your message dated Sat, 24 Jan 2009 18:44:04 -0500
with message-id <87y6x0w9q3.fsf@cyd.mit.edu>
and subject line Re: 23.0.60; Infinite loop in align-regexp
has caused the Emacs bug report #1982,
regarding 23.0.60; Infinite loop in align-regexp
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@emacsbugs.donarmstrong.com
immediately.)


-- 
1982: http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=1982
Emacs Bug Tracking System
Contact owner@emacsbugs.donarmstrong.com with problems

[-- Attachment #2: Type: message/rfc822, Size: 7140 bytes --]

[-- Attachment #2.1.1: Type: text/plain, Size: 2136 bytes --]

This was originally sent to emacs-devel. Since it's been a week with
no response I'm going to assume that that was the wrong place, thus
I'm copying it here. My apologies if the duplication is inappropriate.

For certain choices of regexp and region text, align-regexp will enter
an infinite loop. To reproduce:

  emacs -Q
  RET foo
  C-SPC C-a
  M-x align-regexp
  \<

Note that the infinite loop won't occur for text at the beginning of
the buffer, so make sure to test at least one newline down.

I'm suprised that this hasn't come up before. I would have thought
aligning to beginning-of-word would be a common case. Anyway, the
problem seems to be that align-region assumes that a successful search
will always move point forward. The following patch attempts to fix
this:

--- /home/ggole/src/emacs/lisp/align.el	2009-01-05 12:18:39.000000000 +0900
+++ loopfix-align.el	2009-01-22 08:15:59.000000000 +0900
@@ -1307,6 +1307,7 @@
 		 (rulesep (assq 'separate rule))
 		 (thissep (if rulesep (cdr rulesep) separate))
 		 same (eol 0)
+		 search-origin
 		 group group-c
 		 spacing spacing-c
 		 tab-stop tab-stop-c
@@ -1412,6 +1413,7 @@
 		      ;; while we can find the rule in the alignment
 		      ;; region..
 		      (while (and (< (point) end-mark)
+				  (setq search-origin (point))
 				  (if regfunc
 				      (funcall regfunc end-mark nil)
 				    (re-search-forward regexp
@@ -1436,7 +1438,8 @@
 			;; if the search ended us on the beginning of
 			;; the next line, move back to the end of the
 			;; previous line.
-			(if (bolp)
+			(if (and (bolp)
+				 (> (point) search-origin))
 			    (forward-char -1))

 			;; lookup the `group' attribute the first time
@@ -1576,7 +1579,12 @@
 			    ;; the next line; don't bother searching
 			    ;; anymore on this one
 			    (if (and (not repeat) (not (bolp)))
-				(forward-line)))))
+				(forward-line))
+
+			    ;; if the search did not change point,
+			    ;; move forward to avoid an infinite loop
+			    (if (= (point) search-origin)
+				(forward-char)))))

 		      ;; when they are no more matches for this rule,
 		      ;; align whatever was left over

[-- Attachment #2.1.2: align-regexp-loopfix.diff --]
[-- Type: text/x-patch, Size: 1358 bytes --]

--- /home/ggole/src/emacs/lisp/align.el	2009-01-05 12:18:39.000000000 +0900
+++ loopfix-align.el	2009-01-22 08:15:59.000000000 +0900
@@ -1307,6 +1307,7 @@
 		 (rulesep (assq 'separate rule))
 		 (thissep (if rulesep (cdr rulesep) separate))
 		 same (eol 0)
+		 search-origin
 		 group group-c
 		 spacing spacing-c
 		 tab-stop tab-stop-c
@@ -1412,6 +1413,7 @@
 		      ;; while we can find the rule in the alignment
 		      ;; region..
 		      (while (and (< (point) end-mark)
+				  (setq search-origin (point))
 				  (if regfunc
 				      (funcall regfunc end-mark nil)
 				    (re-search-forward regexp
@@ -1436,7 +1438,8 @@
 			;; if the search ended us on the beginning of
 			;; the next line, move back to the end of the
 			;; previous line.
-			(if (bolp)
+			(if (and (bolp)
+				 (> (point) search-origin))
 			    (forward-char -1))
 
 			;; lookup the `group' attribute the first time
@@ -1576,7 +1579,12 @@
 			    ;; the next line; don't bother searching
 			    ;; anymore on this one
 			    (if (and (not repeat) (not (bolp)))
-				(forward-line)))))
+				(forward-line))
+
+			    ;; if the search did not change point,
+			    ;; move forward to avoid an infinite loop
+			    (if (= (point) search-origin)
+				(forward-char)))))
 
 		      ;; when they are no more matches for this rule,
 		      ;; align whatever was left over

[-- Attachment #3: Type: message/rfc822, Size: 1377 bytes --]

From: Chong Yidong <cyd@stupidchicken.com>
To: Geoff Gole <geoffgole@gmail.com>
Cc: 1982-done@emacsbugs.donarmstrong.com
Subject: Re: 23.0.60; Infinite loop in align-regexp
Date: Sat, 24 Jan 2009 18:44:04 -0500
Message-ID: <87y6x0w9q3.fsf@cyd.mit.edu>

> For certain choices of regexp and region text, align-regexp will enter
> an infinite loop... Anyway, the problem seems to be that align-region
> assumes that a successful search will always move point forward. The
> following patch attempts to fix this:

Your patch looks OK, so I've checked it in.  Thanks very much.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-01-24 23:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <87y6x0w9q3.fsf@cyd.mit.edu>
2009-01-21 23:30 ` bug#1982: 23.0.60; Infinite loop in align-regexp Geoff Gole
2009-01-24 23:50   ` bug#1982: marked as done (23.0.60; Infinite loop in align-regexp) Emacs bug Tracking System

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).