From: Lars Ingebrigtsen <larsi@gnus.org>
To: Noam Postavsky <npostavs@gmail.com>
Cc: stefan monnier <monnier@iro.umontreal.ca>, 35264@debbugs.gnu.org
Subject: bug#35264: "Match data clobbered by buffer modification hooks" when hooks only shifted match-data's markers
Date: Wed, 12 May 2021 16:35:38 +0200 [thread overview]
Message-ID: <8735usj9z9.fsf@gnus.org> (raw)
In-Reply-To: <87a6x5z11g.fsf@gnus.org> (Lars Ingebrigtsen's message of "Fri, 02 Oct 2020 06:47:55 +0200")
Lars Ingebrigtsen <larsi@gnus.org> writes:
>> But the modification hook in question did call save-match-data. As far
>> as I can tell, the problem is that the match-data consists of markers,
>> whose position gets shifted by deletion of characters. The check for
>> this error uses simple integers, so there's no way it can account for
>> this.
>
> That does make sense, but removing this (somewhat buggy) sanity check is
> perhaps a bit scary. Any comments on this?
There were no comments, and the patch no longer applies. I've respun it
now for Emacs 28, and this fixes the case reported in this bug report
(which still reproduces in Emacs 28).
Any comments?
diff --git a/src/search.c b/src/search.c
index c757bf3d1f..df384e1dcf 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2723,7 +2723,6 @@ DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0,
}
newpoint = sub_start + SCHARS (newtext);
- ptrdiff_t newstart = sub_start == sub_end ? newpoint : sub_start;
/* Replace the old text with the new in the cleanest possible way. */
replace_range (sub_start, sub_end, newtext, 1, 0, 1, true);
@@ -2739,11 +2738,11 @@ DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0,
/* The replace_range etc. functions can trigger modification hooks
(see signal_before_change and signal_after_change). Try to error
out if these hooks clobber the match data since clobbering can
- result in confusing bugs. Although this sanity check does not
- catch all possible clobberings, it should catch many of them. */
- if (! (search_regs.num_regs == num_regs
- && search_regs.start[sub] == newstart
- && search_regs.end[sub] == newpoint))
+ result in confusing bugs. We used to check for changes in
+ search_regs start and end, but that fails if modification hooks
+ remove or add text earlier in the buffer, so just check num_regs
+ now. */
+ if (search_regs.num_regs != num_regs)
error ("Match data clobbered by buffer modification hooks");
/* Put point back where it was in the text, if possible. */
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
next prev parent reply other threads:[~2021-05-12 14:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-14 4:40 bug#35264: "Match data clobbered by buffer modification hooks" when hooks only shifted match-data's markers Noam Postavsky
2019-05-30 23:03 ` Noam Postavsky
2020-10-02 4:47 ` Lars Ingebrigtsen
2021-05-12 14:35 ` Lars Ingebrigtsen [this message]
2021-05-12 14:55 ` Eli Zaretskii
2021-05-12 15:43 ` Lars Ingebrigtsen
2021-05-12 15:48 ` Eli Zaretskii
2021-05-12 15:57 ` Lars Ingebrigtsen
2021-05-12 16:03 ` Eli Zaretskii
2021-05-13 9:11 ` Lars Ingebrigtsen
2021-05-13 10:14 ` Eli Zaretskii
2021-05-13 16:03 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-05-13 17:09 ` Eli Zaretskii
2021-05-16 13:20 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8735usj9z9.fsf@gnus.org \
--to=larsi@gnus.org \
--cc=35264@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=npostavs@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.