From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#31888: 27.0.50; Segmentation fault in replace-buffer-contents Date: Sat, 30 Jun 2018 10:44:06 +0300 Message-ID: <83zhzcn2gp.fsf@gnu.org> References: <39638875-4e85-85dc-1cfa-3bfb7321e6b0@zoho.com> <83602bq8hl.fsf@gnu.org> <83bmc1vjn8.fsf@gnu.org> <877emnm97t.fsf@gmail.com> <83muvisyqv.fsf@gnu.org> <83efgpofdu.fsf@gnu.org> <83bmbtobvn.fsf@gnu.org> <838t6xo5sh.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1530344585 2274 195.159.176.226 (30 Jun 2018 07:43:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 30 Jun 2018 07:43:05 +0000 (UTC) Cc: acm@muc.de, 31888@debbugs.gnu.org, joaotavora@gmail.com, k.michal@zoho.com To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jun 30 09:43:00 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fZAX6-0000SB-IZ for geb-bug-gnu-emacs@m.gmane.org; Sat, 30 Jun 2018 09:43:00 +0200 Original-Received: from localhost ([::1]:45993 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fZAZE-0001xr-0g for geb-bug-gnu-emacs@m.gmane.org; Sat, 30 Jun 2018 03:45:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50690) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fZAZ7-0001xj-GL for bug-gnu-emacs@gnu.org; Sat, 30 Jun 2018 03:45:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fZAZ4-0003sr-2i for bug-gnu-emacs@gnu.org; Sat, 30 Jun 2018 03:45:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60624) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fZAZ3-0003sO-VE for bug-gnu-emacs@gnu.org; Sat, 30 Jun 2018 03:45:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fZAZ3-0006gy-O6 for bug-gnu-emacs@gnu.org; Sat, 30 Jun 2018 03:45:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 30 Jun 2018 07:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31888 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 31888-submit@debbugs.gnu.org id=B31888.153034466325656 (code B ref 31888); Sat, 30 Jun 2018 07:45:01 +0000 Original-Received: (at 31888) by debbugs.gnu.org; 30 Jun 2018 07:44:23 +0000 Original-Received: from localhost ([127.0.0.1]:40288 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fZAYQ-0006fk-LD for submit@debbugs.gnu.org; Sat, 30 Jun 2018 03:44:22 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:59617) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fZAYP-0006fV-5Y for 31888@debbugs.gnu.org; Sat, 30 Jun 2018 03:44:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fZAYI-00034Y-Sy for 31888@debbugs.gnu.org; Sat, 30 Jun 2018 03:44:15 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:57794) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fZAY1-0002o1-89; Sat, 30 Jun 2018 03:43:57 -0400 Original-Received: from [176.228.60.248] (port=1799 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1fZAY0-00048R-Mx; Sat, 30 Jun 2018 03:43:57 -0400 In-reply-to: (message from Stefan Monnier on Fri, 29 Jun 2018 16:40:15 -0400) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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: 208.118.235.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:147988 Archived-At: > From: Stefan Monnier > Cc: joaotavora@gmail.com, 31888@debbugs.gnu.org, k.michal@zoho.com, acm@muc.de > Date: Fri, 29 Jun 2018 16:40:15 -0400 > > IIUC replace-buffer-contents is meant to be used in cases where there's > a good probability that the old and new contents are almost identical, > save for a few details here and there. > > So, it may very well be the case that out of the 1MB that is covered by > BEGV..ZV only 10bytes in the middle were deleted/inserted/modified, in > which case running a-c-f on those 10bytes will likely lead to > a significantly more efficient recomputation for things like font-lock. > > This refinement is not indispensable, but we make this effort in pretty > much every other similar circumstance. It's usually fairly easy/cheap > to provide those tighter bounds. Sigh. Does the below look reasonable? diff --git a/src/editfns.c b/src/editfns.c index 4d3c838..9002211 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -3238,9 +3238,21 @@ differences between the two buffers. */) Instead, we announce a single modification for the entire modified region. But don't do that if the caller inhibited modification hooks, because then they don't want that. */ + ptrdiff_t from, to; if (!inhibit_modification_hooks) { - prepare_to_modify_buffer (BEGV, ZV, NULL); + ptrdiff_t k, l; + + /* Find the first character position to be changed. */ + for (k = 0; k < size_a && !bit_is_set (ctx.deletions, k); k++) + ; + from = BEGV + k; + + /* Find the last character position to be changed. */ + for (l = size_a; l > 0 && !bit_is_set (ctx.deletions, l - 1); l--) + ; + to = BEGV + l; + prepare_to_modify_buffer (from, to, NULL); specbind (Qinhibit_modification_hooks, Qt); modification_hooks_inhibited = true; } @@ -3293,8 +3305,9 @@ differences between the two buffers. */) if (modification_hooks_inhibited) { - signal_after_change (BEGV, size_a, ZV - BEGV); - update_compositions (BEGV, ZV, CHECK_BORDER); + ptrdiff_t updated_to = to + ZV - BEGV - size_a; + signal_after_change (from, to - from, updated_to - from); + update_compositions (from, updated_to, CHECK_INSIDE); } return Qnil;