From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#36328: 26.2; Args out of range on search-and-replace of *.cc file Date: Tue, 25 Jun 2019 09:47:08 +0000 Message-ID: <20190625094708.GB5471@ACM> References: <20190622205033.GA9167@ACM> <20190623122207.GA4736@ACM> <20190623193258.GB4736@ACM> <87k1dc2e5h.fsf@mail.linkov.net> <20190624075218.GA4781@ACM> <87d0j27wiu.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="91777"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: Jayden Navarro , 36328@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jun 25 11:48: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.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hfi3p-000Nlh-IR for geb-bug-gnu-emacs@m.gmane.org; Tue, 25 Jun 2019 11:48:21 +0200 Original-Received: from localhost ([::1]:58134 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfi3o-0007RB-3r for geb-bug-gnu-emacs@m.gmane.org; Tue, 25 Jun 2019 05:48:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54095) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfi3Y-0007Qv-1n for bug-gnu-emacs@gnu.org; Tue, 25 Jun 2019 05:48:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hfi3W-0004KI-2N for bug-gnu-emacs@gnu.org; Tue, 25 Jun 2019 05:48:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45108) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hfi3V-0004Jz-Tf for bug-gnu-emacs@gnu.org; Tue, 25 Jun 2019 05:48:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hfi3V-0005Ac-Oi for bug-gnu-emacs@gnu.org; Tue, 25 Jun 2019 05:48:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 25 Jun 2019 09:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36328 X-GNU-PR-Package: emacs Original-Received: via spool by 36328-submit@debbugs.gnu.org id=B36328.156145604119824 (code B ref 36328); Tue, 25 Jun 2019 09:48:01 +0000 Original-Received: (at 36328) by debbugs.gnu.org; 25 Jun 2019 09:47:21 +0000 Original-Received: from localhost ([127.0.0.1]:58652 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hfi2r-00059g-3k for submit@debbugs.gnu.org; Tue, 25 Jun 2019 05:47:21 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:61492 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1hfi2o-00059W-LZ for 36328@debbugs.gnu.org; Tue, 25 Jun 2019 05:47:19 -0400 Original-Received: (qmail 26932 invoked by uid 3782); 25 Jun 2019 09:47:10 -0000 Original-Received: from acm.muc.de (p4FE15DD6.dip0.t-ipconnect.de [79.225.93.214]) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 25 Jun 2019 11:47:08 +0200 Original-Received: (qmail 5501 invoked by uid 1000); 25 Jun 2019 09:47:08 -0000 Content-Disposition: inline In-Reply-To: <87d0j27wiu.fsf@mail.linkov.net> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de 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:161330 Archived-At: Hello, Juri. On Mon, Jun 24, 2019 at 22:18:53 +0300, Juri Linkov wrote: > Hello, Alan. > >> I think first we should try to narrow down the source of this match > >> data leak. > > Is there really such a thing as a match data leak? I don't think > > there's any convention that the match data are preserved over large > > bits of code, particularly when different libraries are involved. > > There is nothing documented in the Elisp manual that I can see. > Yes, it seems such match-data leak is considered at least undesirable. > I remember efforts to replace string-match with string-match-p in > potentially unsafe places and to wrap more code in save-match-data. > But I guess such efforts are futile since this task is endless. I think so, too. I remembered being puzzled in my early Emacs days, wondering whether the save-match-data should go in the function which messes it up, or the function which cares about it. > Usually it's enough for a function that cares about preserving > match-data to protect it from mutation. I now think this is the best place to put save-match-data. > >> Then we could decide what is the best solution. Currently I see no > >> such place in isearch-lazy-highlight-new-loop that calls external > >> code. > > isearch-lazy-highlight-new-loop calls (sit-for 0), which calls > > redisplay, which calls font locking. > You are right that it's too much to expect that the match-data will be > preserved after redisplay, and we can't find and fix all places that > change match-data, so save-match-data needs be added to perform-replace > somewhere to protect match-data. Yes, I think so. > Since (sit-for 0) is unsafe for match-data, the first candidate to be > wrapped in save-match-data is (sit-for 0) itself in > isearch-lazy-highlight-new-loop. > But perhaps more correct would be to use save-match-data in the same > function that cares about preserving its match-data, so the second > candidate to use save-match-data is perform-replace. Then the need > of using save-match-data will be self-evident for everyone who will > look at the code in perform-replace: here we use match-data, and here > we protect it in the same function. My feeling is that perform-replace (or, possibly, replace-highlight) is the best place to put a save-match-data. -- Alan Mackenzie (Nuremberg, Germany).