unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@gmail.com>
To: 35264@debbugs.gnu.org
Cc: stefan monnier <monnier@iro.umontreal.ca>
Subject: bug#35264: "Match data clobbered by buffer modification hooks" when hooks only shifted match-data's markers
Date: Thu, 30 May 2019 19:03:54 -0400	[thread overview]
Message-ID: <871s0f7det.fsf@gmail.com> (raw)
In-Reply-To: <87h8b119oy.fsf@gmail.com> (Noam Postavsky's message of "Sun, 14 Apr 2019 00:40:13 -0400")

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


> I think this is a variant of Bug#23917, there was some talk there about
> removing the check, perhaps that is the right solution.

So, this, I guess.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2381 bytes --]

From 6fd6605c63ecc031a3fd6ba8b8e2e754c183b3f2 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Thu, 30 May 2019 19:00:31 -0400
Subject: [PATCH] Remove unreliable test for match data clobbering (Bug#35264)

* src/search.c (Freplace_match): Don't test for change in search_regs
start and end, this is unreliable if change hooks modify text earlier
in the buffer.
---
 src/search.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/src/search.c b/src/search.c
index db7fecd9ba..1d4550849e 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2730,22 +2730,16 @@ DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0,
   /* The functions below modify the buffer, so they could trigger
      various modification hooks (see signal_before_change and
      signal_after_change).  If these hooks clobber the match data we
-     error out since otherwise this will result in confusing bugs.  */
-  ptrdiff_t sub_start = search_regs.start[sub];
-  ptrdiff_t sub_end = search_regs.end[sub];
+     error out since otherwise this will 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.  */
   unsigned  num_regs = search_regs.num_regs;
   newpoint = search_regs.start[sub] + SCHARS (newtext);
 
   /* Replace the old text with the new in the cleanest possible way.  */
   replace_range (search_regs.start[sub], search_regs.end[sub],
                  newtext, 1, 0, 1, 1);
-  /* Update saved data to match adjustment made by replace_range.  */
-  {
-    ptrdiff_t change = newpoint - sub_end;
-    if (sub_start >= sub_end)
-      sub_start += change;
-    sub_end += change;
-  }
 
   if (case_action == all_caps)
     Fupcase_region (make_number (search_regs.start[sub]),
@@ -2755,9 +2749,7 @@ DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0,
     Fupcase_initials_region (make_number (search_regs.start[sub]),
 			     make_number (newpoint));
 
-  if (search_regs.start[sub] != sub_start
-      || search_regs.end[sub] != sub_end
-      || search_regs.num_regs != num_regs)
+  if (search_regs.num_regs != num_regs)
     error ("Match data clobbered by buffer modification hooks");
 
   /* Put point back where it was in the text.  */
-- 
2.11.0


  reply	other threads:[~2019-05-30 23:03 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 [this message]
2020-10-02  4:47   ` Lars Ingebrigtsen
2021-05-12 14:35     ` Lars Ingebrigtsen
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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871s0f7det.fsf@gmail.com \
    --to=npostavs@gmail.com \
    --cc=35264@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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 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).