From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs 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 Message-ID: <8735usj9z9.fsf@gnus.org> References: <87h8b119oy.fsf@gmail.com> <871s0f7det.fsf@gmail.com> <87a6x5z11g.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23225"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: stefan monnier , 35264@debbugs.gnu.org To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed May 12 16:41:05 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lgq2r-0005uK-87 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 12 May 2021 16:41:05 +0200 Original-Received: from localhost ([::1]:41034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgq2q-0002O7-8K for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 12 May 2021 10:41:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgpxy-0006C4-2M for bug-gnu-emacs@gnu.org; Wed, 12 May 2021 10:36:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56687) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lgpxx-0007Jy-QN for bug-gnu-emacs@gnu.org; Wed, 12 May 2021 10:36:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lgpxx-0001pn-NY for bug-gnu-emacs@gnu.org; Wed, 12 May 2021 10:36:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 12 May 2021 14:36:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35264 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 35264-submit@debbugs.gnu.org id=B35264.16208301527033 (code B ref 35264); Wed, 12 May 2021 14:36:01 +0000 Original-Received: (at 35264) by debbugs.gnu.org; 12 May 2021 14:35:52 +0000 Original-Received: from localhost ([127.0.0.1]:40000 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lgpxo-0001pN-2s for submit@debbugs.gnu.org; Wed, 12 May 2021 10:35:52 -0400 Original-Received: from quimby.gnus.org ([95.216.78.240]:59302) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lgpxl-0001p6-42 for 35264@debbugs.gnu.org; Wed, 12 May 2021 10:35:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:Date:References: In-Reply-To:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=z3iwCZZfKxFAiAWQO/4YJjkK3g70lhODoBI/UVKaBHA=; b=tXvz6NryY7N+bfq4IcYNiuVumk BoEpCF3xGy+s4VM/XwDfe1LFgb/+7n1CZIK+Wdkw/ckGdBj7geq1HAp/R0C4TIjCOAujNHdcu4qN+ 16+/QcTgIk3a17+Y3kD+rqOgJd2ALxAXtSii9jNiBULH82lXf7JsbNosCAFVK8chib/Y=; Original-Received: from cm-84.212.220.105.getinternet.no ([84.212.220.105] helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lgpxb-0005cc-Bc; Wed, 12 May 2021 16:35:41 +0200 In-Reply-To: <87a6x5z11g.fsf@gnus.org> (Lars Ingebrigtsen's message of "Fri, 02 Oct 2020 06:47:55 +0200") X-Now-Playing: Fire!'s _Defeat_: "Each millimeter of the toad, part 2" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:206330 Archived-At: Lars Ingebrigtsen 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