GNU bug report logs -
#54218
[PATCH] Magic number regexp shouldn't match beyond end-of-line.
Previous Next
Reported by: "Andrew L. Moore" <slewsys <at> gmail.com>
Date: Wed, 2 Mar 2022 04:53:01 UTC
Severity: normal
Tags: patch
Fixed in version 29.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 54218 in the body.
You can then email your comments to 54218 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#54218
; Package
emacs
.
(Wed, 02 Mar 2022 04:53:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
"Andrew L. Moore" <slewsys <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Wed, 02 Mar 2022 04:53:01 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Repeat magic number search to work around match-data loss
when `save-window-excursion' is called.
---
lisp/progmodes/executable.el | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/lisp/progmodes/executable.el b/lisp/progmodes/executable.el
index d7c093444e..9116bdea9d 100644
--- a/lisp/progmodes/executable.el
+++ b/lisp/progmodes/executable.el
@@ -232,7 +232,8 @@ executable-set-magic
(save-excursion
(goto-char (point-min))
(add-hook 'after-save-hook 'executable-chmod nil t)
- (if (looking-at "#![ \t]*\\(.*\\)$")
+ ;; Regexp shouldn't match beyond end-of-line.
+ (if (looking-at "#![ \t]*\\([^\n]*\\)$")
(and (goto-char (match-beginning 1))
;; If the line ends in a space,
;; don't offer to change it.
@@ -247,8 +248,13 @@ executable-set-magic
"Replace magic number by `#!%s'? "
argument))))
(progn
- (replace-match argument t t nil 1)
- (message "Magic number changed to `#!%s'"
argument))))
+ ;; Repeat search to work around match-data loss
+ ;; from call to `save-window-excursion' above.
+ (goto-char (point-min))
+ (if (looking-at "^#![ \t]*\\([^\n]*\\)$")
+ (progn
+ (replace-match argument t t nil 1)
+ (message "Magic number changed to `#!%s'"
argument))))))
(insert "#!" argument ?\n)
(message "Magic number changed to `#!%s'" argument))))
interpreter)
--
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#54218
; Package
emacs
.
(Wed, 02 Mar 2022 08:24:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 54218 <at> debbugs.gnu.org (full text, mbox):
On Mär 01 2022, Andrew L. Moore wrote:
> diff --git a/lisp/progmodes/executable.el b/lisp/progmodes/executable.el
> index d7c093444e..9116bdea9d 100644
> --- a/lisp/progmodes/executable.el
> +++ b/lisp/progmodes/executable.el
> @@ -232,7 +232,8 @@ executable-set-magic
> (save-excursion
> (goto-char (point-min))
> (add-hook 'after-save-hook 'executable-chmod nil t)
> - (if (looking-at "#![ \t]*\\(.*\\)$")
> + ;; Regexp shouldn't match beyond end-of-line.
> + (if (looking-at "#![ \t]*\\([^\n]*\\)$")
In Emacs regexps, `.' doesn't match newlines.
--
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#54218
; Package
emacs
.
(Thu, 03 Mar 2022 14:43:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 54218 <at> debbugs.gnu.org (full text, mbox):
"Andrew L. Moore" <slewsys <at> gmail.com> writes:
> Repeat magic number search to work around match-data loss
> when `save-window-excursion' is called.
I think it would perhaps make more sense to just save the match data
instead of repeating the match, so I've now done so in Emacs 29
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
bug marked as fixed in version 29.1, send any further explanations to
54218 <at> debbugs.gnu.org and "Andrew L. Moore" <slewsys <at> gmail.com>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Thu, 03 Mar 2022 14:43:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#54218
; Package
emacs
.
(Thu, 03 Mar 2022 19:58:01 GMT)
Full text and
rfc822 format available.
Message #16 received at 54218 <at> debbugs.gnu.org (full text, mbox):
On 3/3/22 09:42, Lars Ingebrigtsen wrote:
> "Andrew L. Moore" <slewsys <at> gmail.com> writes:
>
>> Repeat magic number search to work around match-data loss
>> when `save-window-excursion' is called.
>
> I think it would perhaps make more sense to just save the match data
> instead of repeating the match, so I've now done so in Emacs 29
Yes, this resolves the issues that I was seeing.
For the record, I'm not able to reproduce the data loss with
vanilla Emacs by calling `executable-set-magic' manually. It
occurs (for me) when `executable-set-magic' is called automatically
from a minor mode. In any case, your patch fixes my minor mode
and does no harm.
The other issue that I attributed to the regexp matching beyond
EOL was caused by `replace-match' being called by incorrect or
uninitialized match data. Your patch resolves this as well.
Thank you!
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#54218
; Package
emacs
.
(Fri, 04 Mar 2022 15:38:02 GMT)
Full text and
rfc822 format available.
Message #19 received at 54218 <at> debbugs.gnu.org (full text, mbox):
"Andrew L. Moore" <slewsys <at> gmail.com> writes:
> The other issue that I attributed to the regexp matching beyond
> EOL was caused by `replace-match' being called by incorrect or
> uninitialized match data. Your patch resolves this as well.
Thanks for checking.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 02 Apr 2022 11:24:03 GMT)
Full text and
rfc822 format available.
This bug report was last modified 3 years and 77 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.