From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs 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 Message-ID: <871s0f7det.fsf@gmail.com> References: <87h8b119oy.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="120494"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) Cc: stefan monnier To: 35264@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri May 31 01:05:22 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hWU6r-000V72-55 for geb-bug-gnu-emacs@m.gmane.org; Fri, 31 May 2019 01:05:21 +0200 Original-Received: from localhost ([127.0.0.1]:60147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWU6k-0001EC-QX for geb-bug-gnu-emacs@m.gmane.org; Thu, 30 May 2019 19:05:14 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:44858) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWU6d-0001Df-CG for bug-gnu-emacs@gnu.org; Thu, 30 May 2019 19:05:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWU6b-0007py-CF for bug-gnu-emacs@gnu.org; Thu, 30 May 2019 19:05:07 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49008) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hWU6Y-0007n4-4K for bug-gnu-emacs@gnu.org; Thu, 30 May 2019 19:05:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hWU6X-0000YW-SN for bug-gnu-emacs@gnu.org; Thu, 30 May 2019 19:05:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 30 May 2019 23:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35264 X-GNU-PR-Package: emacs Original-Received: via spool by 35264-submit@debbugs.gnu.org id=B35264.15592574452055 (code B ref 35264); Thu, 30 May 2019 23:05:01 +0000 Original-Received: (at 35264) by debbugs.gnu.org; 30 May 2019 23:04:05 +0000 Original-Received: from localhost ([127.0.0.1]:34318 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hWU5c-0000X5-QM for submit@debbugs.gnu.org; Thu, 30 May 2019 19:04:05 -0400 Original-Received: from mail-it1-f182.google.com ([209.85.166.182]:39899) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hWU5a-0000WX-0a for 35264@debbugs.gnu.org; Thu, 30 May 2019 19:04:03 -0400 Original-Received: by mail-it1-f182.google.com with SMTP id j204so6893880ite.4 for <35264@debbugs.gnu.org>; Thu, 30 May 2019 16:04:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=uPI4KOQe9rq+2EMxvVflJUtWVIHqOAa0RqZWYYjnu7A=; b=o4Af/+OYqabOf33LYZGYKCyH3L4J+UyiY+X3UXBYdAiHfqhozErz0eNdTrhjKPYTMe NKpAf0Oj4gASFMBI7qnngjhfoIkO7ifzxnSLADVkN+j86YV9aMIXtXUyJ7X04Gz1Macy oHFsZHpOCtmTE9q2k9SbDhPpcwbVglSxKtsFw0R7+jsfXEEgUtg86iJxSwhGimU+dJ5j sOBWHHAXRB+B2YaiHtpFXk/QFnTyXKKLmWgOdyhvs24ne/BvSQo3rQ5Tdo9WkBreiuED 8jnCXHcu+F+tQ38T+CzPoSYsIbJGcU8omdC4VpLed5GoRpflncppCPviFNKqpM5K183B SlPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=uPI4KOQe9rq+2EMxvVflJUtWVIHqOAa0RqZWYYjnu7A=; b=KuzdZJsOhWwFxqnny+I0a8ProiGHHluvCBjok1VFVptLt9pENG2WZYXdE1+p6qdnbn GRJyAh0GT33y9S522LlmD03UfkTOglk0ZLV/5VzUXGzc7yvFEDLNj95uThUrS9UEnIP2 hjupXQVkjK/VF0sR//bh5+Js8BSgv8n0JjQVKJpj4F+kev/ufsoQXoD/Dw16pnGspSZP M/R7DMmPwHY6EHoKAiakP6MgHVvxbsVtnwd5OHk3/uAlALDRs+FTHrregAVwlMyEZWTd IUg0B9uiXYEyybfbTyZSPqEx8yS+qg99KQyWqyFtkoPldFvqKQb+I9Qn8mszbx8Pa3uu fa2Q== X-Gm-Message-State: APjAAAUNMdLD5f0+b9OmDg9mqWx3UJLQp5z8289asTLuv5vVGiBNGX+d 2pkYFoRctNGWJ4u2ob5EAAo= X-Google-Smtp-Source: APXvYqwlA5xggJ8h4djSsnldTAJQr+xfPXt5RE3RBtKKR7DjSHZQNC9svppZDr0iRMfwn6eQh9a8HQ== X-Received: by 2002:a24:64c6:: with SMTP id t189mr5012622itc.161.1559257436427; Thu, 30 May 2019 16:03:56 -0700 (PDT) Original-Received: from minid (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.gmail.com with ESMTPSA id u134sm1777255itb.32.2019.05.30.16.03.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 May 2019 16:03:55 -0700 (PDT) In-Reply-To: <87h8b119oy.fsf@gmail.com> (Noam Postavsky's message of "Sun, 14 Apr 2019 00:40:13 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:159954 Archived-At: --=-=-= Content-Type: text/plain > 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Remove-unreliable-test-for-match-data-clobbering-Bug.patch Content-Description: patch >From 6fd6605c63ecc031a3fd6ba8b8e2e754c183b3f2 Mon Sep 17 00:00:00 2001 From: Noam Postavsky 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 --=-=-=--