From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#36431: Crash in marker.c:337 Date: Sat, 29 Jun 2019 18:56:53 -0400 Message-ID: References: <20190629.131734.877718102639559715.wl@gnu.org> <831rzch9nd.fsf@gnu.org> <83zhm0fuqg.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="168302"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 36431@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jun 30 00:58:12 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 1hhMIL-000hcC-Ry for geb-bug-gnu-emacs@m.gmane.org; Sun, 30 Jun 2019 00:58:10 +0200 Original-Received: from localhost ([::1]:42372 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhMIK-0006uK-9M for geb-bug-gnu-emacs@m.gmane.org; Sat, 29 Jun 2019 18:58:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59957) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhMIF-0006uD-4K for bug-gnu-emacs@gnu.org; Sat, 29 Jun 2019 18:58:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hhMID-0004Ze-Tb for bug-gnu-emacs@gnu.org; Sat, 29 Jun 2019 18:58:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59737) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hhMID-0004ZT-Pi for bug-gnu-emacs@gnu.org; Sat, 29 Jun 2019 18:58:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hhMID-00070G-NO for bug-gnu-emacs@gnu.org; Sat, 29 Jun 2019 18:58:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 29 Jun 2019 22:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36431 X-GNU-PR-Package: emacs Original-Received: via spool by 36431-submit@debbugs.gnu.org id=B36431.156184902426859 (code B ref 36431); Sat, 29 Jun 2019 22:58:01 +0000 Original-Received: (at 36431) by debbugs.gnu.org; 29 Jun 2019 22:57:04 +0000 Original-Received: from localhost ([127.0.0.1]:45048 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hhMHH-0006z8-PA for submit@debbugs.gnu.org; Sat, 29 Jun 2019 18:57:04 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:50394) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hhMHG-0006yf-KG for 36431@debbugs.gnu.org; Sat, 29 Jun 2019 18:57:03 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 18340444304; Sat, 29 Jun 2019 18:56:57 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id A95C04442E3; Sat, 29 Jun 2019 18:56:55 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1561849015; bh=aN8kPCM7Tn8/npQ16FFXMvqft2yezn6VSkGfdiErTTs=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=pmggYLsluMzwDsOKFX+dSOsCExxmaJ8PSS0ux85ZGzqeXicc8ZTDca1lQOFYiPgaJ 4fBxr8zewwpItzsvi4iQ/wyS1g3C8RKFCxFWrut3bybA//J3OK2wZvMwyC8LOVy0BI UUiX9kvWAswdWU20HpKgOPzIZS1iGxTIwmQhNWEUn87FjIfQmMKzGFzw1Q7g0kAce4 mCxcN1TlHL+onPF2C/JBnOXwuoNPhW2vk2I+DPzE7N+bl0WkHM4U0mP9Pzik10E/mO 2KGMrEmm7E607zGBoeWrxiRELIf1FOdzK1C5RiYHIIO9/k9NqNm54OrjYb8IiSP/YD WEIbBOzkDxPSA== Original-Received: from alfajor (76-10-151-214.dsl.teksavvy.com [76.10.151.214]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 50F99120C68; Sat, 29 Jun 2019 18:56:55 -0400 (EDT) In-Reply-To: <83zhm0fuqg.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 29 Jun 2019 15:20:55 +0300") 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:161849 Archived-At: >> > while sending an e-mail with `mew', I get the attached crash. This is >> > something new, which I haven't experienced before. I can reliably >> > repeat it. Hmm... indeed insert-file-contents takes some shortcuts when inserting the new text into the buffer which can break the expected invariants. I don't really know how to reproduce your bug, but I think I have an idea of what might be going on. Can you try the patch below, to see if it fixes your problem? Stefan diff --git a/src/fileio.c b/src/fileio.c index ed1d2aedf3..a7be05ef5c 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -3741,6 +3741,7 @@ because (1) it preserves some marker positions and (2) it puts less data CHECK_CODING_SYSTEM (Vcoding_system_for_read); Fset (Qbuffer_file_coding_system, Vcoding_system_for_read); } + eassert (inserted == 0); goto notfound; } @@ -3767,7 +3768,10 @@ because (1) it preserves some marker positions and (2) it puts less data not_regular = 1; if (! NILP (visit)) - goto notfound; + { + eassert (inserted == 0); + goto notfound; + } if (! NILP (replace) || ! NILP (beg) || ! NILP (end)) xsignal2 (Qfile_error, @@ -4435,19 +4439,6 @@ because (1) it preserves some marker positions and (2) it puts less data if (how_much < 0) report_file_error ("Read error", orig_filename); - /* Make the text read part of the buffer. */ - GAP_SIZE -= inserted; - GPT += inserted; - GPT_BYTE += inserted; - ZV += inserted; - ZV_BYTE += inserted; - Z += inserted; - Z_BYTE += inserted; - - if (GAP_SIZE > 0) - /* Put an anchor to ensure multi-byte form ends at gap. */ - *GPT_ADDR = 0; - notfound: if (NILP (coding_system)) @@ -4457,6 +4448,7 @@ because (1) it preserves some marker positions and (2) it puts less data Note that we can get here only if the buffer was empty before the insertion. */ + eassert (Z == BEG); if (!NILP (Vcoding_system_for_read)) coding_system = Vcoding_system_for_read; @@ -4477,6 +4469,16 @@ because (1) it preserves some marker positions and (2) it puts less data bset_undo_list (current_buffer, Qt); record_unwind_protect (decide_coding_unwind, unwind_data); + /* Make the text read part of the buffer. */ + eassert (NILP (BVAR (current_buffer, enable_multibyte_characters))); + GAP_SIZE -= inserted; + GPT += inserted; + GPT_BYTE += inserted; + ZV += inserted; + ZV_BYTE += inserted; + Z += inserted; + Z_BYTE += inserted; + if (inserted > 0 && ! NILP (Vset_auto_coding_function)) { coding_system = call2 (Vset_auto_coding_function, @@ -4493,8 +4495,18 @@ because (1) it preserves some marker positions and (2) it puts less data if (CONSP (coding_system)) coding_system = XCAR (coding_system); } - unbind_to (count1, Qnil); + + /* Move the text back into the gap. Do it now, before we set the + buffer back to multibyte, since the bytes may very well not be + valid for a multibyte buffer. */ + set_point_both (BEG, BEG_BYTE); + move_gap_both (BEG, BEG_BYTE); inserted = Z_BYTE - BEG_BYTE; + GAP_SIZE += inserted; + ZV = Z = BEG; + ZV_BYTE = Z_BYTE = BEG_BYTE; + + unbind_to (count1, Qnil); } if (NILP (coding_system)) @@ -4528,22 +4540,28 @@ because (1) it preserves some marker positions and (2) it puts less data } } + eassert (PT == GPT); + coding.dst_multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); if (CODING_MAY_REQUIRE_DECODING (&coding) && (inserted > 0 || CODING_REQUIRE_FLUSHING (&coding))) { - move_gap_both (PT, PT_BYTE); - GAP_SIZE += inserted; - ZV_BYTE -= inserted; - Z_BYTE -= inserted; - ZV -= inserted; - Z -= inserted; decode_coding_gap (&coding, inserted, inserted); inserted = coding.produced_char; coding_system = CODING_ID_NAME (coding.id); } else if (inserted > 0) { + /* Make the text read part of the buffer. */ + eassert (NILP (BVAR (current_buffer, enable_multibyte_characters))); + GAP_SIZE -= inserted; + GPT += inserted; + GPT_BYTE += inserted; + ZV += inserted; + ZV_BYTE += inserted; + Z += inserted; + Z_BYTE += inserted; + invalidate_buffer_caches (current_buffer, PT, PT + inserted); adjust_after_insert (PT, PT_BYTE, PT + inserted, PT_BYTE + inserted, inserted);