From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eli Zaretskii Subject: =?UTF-8?B?YnVnIzIzOTE3OiBQbGVhc2UgY29uc2lkZXIgbWFraW5nIEJ1ZyAj?= =?UTF-8?B?MjM5MTcgYSBibG9ja2VyIGZvciAyNS4xICh3YXMgUmU6IG9yZy1jYXB0dXJl?= =?UTF-8?B?OiBDYXB0dXJlIHRlbXBsYXRlIOKAmGfigJk6IE1hdGNoIGRhdGEgY2xvYmJl?= =?UTF-8?B?cmVkIGJ5IGJ1ZmZlciBtb2RpZmljYXRpb24gaG9va3Mp?= Date: Tue, 19 Jul 2016 05:40:11 +0300 Message-ID: <83eg6q1hbo.fsf__43251.5168017291$1468896655$gmane$org@gnu.org> References: <87vb066ejv.fsf@linaro.org> <8360s67qcp.fsf@gnu.org> <87bn1yyaui.fsf@linaro.org> <87mvlhmv0x.fsf_-_@moondust.awandering> <837fcl5zs9.fsf@gnu.org> <87a8hgkwcb.fsf@linaro.org> <8360s42mcb.fsf@gnu.org> <87eg6rgmlg.fsf@gmail.com> <83lh0y24y6.fsf@gnu.org> Reply-To: Eli Zaretskii Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPKy0-0001hu-Ie for emacs-orgmode@gnu.org; Mon, 18 Jul 2016 22:41:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPKxy-00081v-HP for emacs-orgmode@gnu.org; Mon, 18 Jul 2016 22:41:03 -0400 Sender: "Debbugs-submit" Resent-Message-ID: In-reply-to: (message from Stefan Monnier on Mon, 18 Jul 2016 20:58:35 -0400) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Stefan Monnier Cc: 23917@debbugs.gnu.org, rpluim@gmail.com, jwiegley@gmail.com, alex.bennee@linaro.org, nljlistbox2@gmail.com > From: Stefan Monnier > Cc: Robert Pluim , 23917@debbugs.gnu.org, alex.bennee@linaro.org, jwiegley@gmail.com, nljlistbox2@gmail.com > Date: Mon, 18 Jul 2016 20:58:35 -0400 > > > In the case in point, a single character at EOB (= 62) was deleted, > > which made EOB be 61, one less than its previous value. When > > save-match-data was called from within a hook set up by Org, it tried > > to record the end of the sub-expression as 62, but set-marker silently > > changed that to 61. That "corrected" value was subsequently restored > > when save-match-data was exited, whereas replace-match expected to see > > the original value of 62, and therefore barfed. > > I think this change performed by save-match-data is harmless: the old > value (62) was not valid any more anyway. In this particular case, yes. But only in this case, because (a) there's actually only one sub-expression, and (b) it ends exactly at EOB. The more general problem is when there's at least one more sub-expression, whose start and/or end are after the new EOB. Those sub-expression's data will be completely bogus after the adjustment, should the buffer-modification hooks use save-match-data. > So I think a safe fix is to try and relax the check we added to > replace-match so it doesn't get all worked up when something ≥ EOB gets > changed to something else that's also ≥ EOB. And lose the other sub-expressions in a more general case? Really? > Or maybe instead of signaling an error, we could simply skip the "Adjust > search data for this change". That would still sweep the problem under the carpet, leaving the match data bogus, so I don't like doing that. > This said, I don't fully understand what's going on: bug#23869 reported > a crash, but AFAICT the match-data here is only used to adjust > search_regs which seems like it wouldn't cause a crash, even if the new > values are bogus. The crash in bug#23869 was due to this: newpoint = search_regs.start[sub] + SCHARS (newtext); [...] /* Now move point "officially" to the start of the inserted replacement. */ move_if_not_intangible (newpoint); <<<<<<<<<<<<<<<<<<<<<<< because due to clobbering, newpoint became -1. > > - '((save-match-data-internal (match-data))) > > + '((save-match-data-internal (match-data 'integers))) > > That looks risky. Then how about manually doing the equivalent of save-match-data around the call to replace_range, calling match-data with non-nil argument?