From unknown Fri Aug 15 01:57:24 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#15907 <15907@debbugs.gnu.org> To: bug#15907 <15907@debbugs.gnu.org> Subject: Status: 24.3; Emacs crash due to substitute-command-keys and after-change-functions Reply-To: bug#15907 <15907@debbugs.gnu.org> Date: Fri, 15 Aug 2025 08:57:24 +0000 retitle 15907 24.3; Emacs crash due to substitute-command-keys and after-ch= ange-functions reassign 15907 emacs submitter 15907 Artur Malabarba severity 15907 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Nov 15 17:05:03 2013 Received: (at submit) by debbugs.gnu.org; 15 Nov 2013 22:05:03 +0000 Received: from localhost ([127.0.0.1]:56284 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VhRVc-0008Gg-FA for submit@debbugs.gnu.org; Fri, 15 Nov 2013 17:05:03 -0500 Received: from eggs.gnu.org ([208.118.235.92]:57846) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VhQsG-0007Ft-Le for submit@debbugs.gnu.org; Fri, 15 Nov 2013 16:24:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VhQs5-0001cH-M9 for submit@debbugs.gnu.org; Fri, 15 Nov 2013 16:24:15 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:45814) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VhQs5-0001c0-IW for submit@debbugs.gnu.org; Fri, 15 Nov 2013 16:24:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VhQrz-00054k-MD for bug-gnu-emacs@gnu.org; Fri, 15 Nov 2013 16:24:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VhQrt-0001Wq-Sf for bug-gnu-emacs@gnu.org; Fri, 15 Nov 2013 16:24:03 -0500 Received: from mail-we0-x233.google.com ([2a00:1450:400c:c03::233]:52623) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VhQrt-0001Vv-Kl for bug-gnu-emacs@gnu.org; Fri, 15 Nov 2013 16:23:57 -0500 Received: by mail-we0-f179.google.com with SMTP id q59so1980266wes.38 for ; Fri, 15 Nov 2013 13:23:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:message-id:to:subject:from:mime-version:content-type :content-transfer-encoding; bh=aQDCfijX/JtE9L5J0j5D0dU5jO+3gIob3LUFJ1fJiNc=; b=vBwMHt9uPPXBsmGqaeiJyGuYVV6PfK06DNtqQwQFjx3GFWnfT4eCjp30WWh6TNoiNx 75ChtNFCKBBucxLDXjZI11G1F3KwIHpaNlu7QJZIyKuDl97i0cQCU9rZl6y6YwFaO7eP +Q8dSBkhzYcPxqAECxpECMo2Ms9hzUNXNmQnQ1nEZ5IXWwbHj7YtkQ4dXOv3AA7rUcFq +047M1M2McKXK7GNj/93H7nsvOrpDzGw8lTQoUIB7hXj2hGAtkSjg7X3DBccHwh7ss0x YduZfKt7/wioyhQBch1zFycSZtfhGMNdIBtx85fcm8AK/SwbUcEAB3lZygnFvdcOt/Ma jtUQ== X-Received: by 10.194.171.34 with SMTP id ar2mr1363717wjc.81.1384550636328; Fri, 15 Nov 2013 13:23:56 -0800 (PST) Received: from localhost (host-78-146-114-249.as13285.net. [78.146.114.249]) by mx.google.com with ESMTPSA id gb1sm8828527wic.0.2013.11.15.13.23.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Nov 2013 13:23:55 -0800 (PST) Date: Fri, 15 Nov 2013 21:23:01 +0000 (GMT) Message-Id: <20131115.212301.505338034.artur.malabarba@gmail.com> To: bug-gnu-emacs@gnu.org Subject: 24.3; Emacs crash due to substitute-command-keys and after-change-functions From: Artur Malabarba X-Mailer: Mew version 6.5 on Emacs 24.3 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Fri, 15 Nov 2013 17:04:59 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) Emacs crashes whenever `substitute-command-keys' is invoked and one of the functions in `after-change-functions' contains a call similar to `(format "%s" 1)'. To reproduce: 1. Start `emacs -Q'; 2. Evaluate the following two statements: (add-hook 'after-change-functions (lambda (&rest a) (format "%s"= 1))) (substitute-command-keys "\\{emacs-lisp-mode-map}") 3. That's it. Emacs crashes. The crash doesn't happen if you replace the number 1 with a string or a symbol, but it does also happen if you replace it with a list. This is most annoying as it causes a crash whenever `describe-mode' is invoked. In GNU Emacs 24.3.1 (i686-pc-linux-gnu, GTK+ Version 3.8.2) of 2013-08-06 on -mnt-storage-buildroots-staging-i686-eric Windowing system distributor `The X.Org Foundation', version 11.0.11403= 000 Configured using: `configure '--prefix=3D/usr' '--sysconfdir=3D/etc' '--libexecdir=3D/usr/lib' '--localstatedir=3D/var' '--with-x-toolkit=3Dgtk3' '--with-xft' 'CFLAGS=3D-march=3Di686 -mtune=3Dgeneric -O2 -pipe -fstack-protector --param=3Dssp-buffer-size= =3D4' 'LDFLAGS=3D-Wl,-O1,--sort-common,--as-needed,-z,relro' 'CPPFLAGS=3D-D_FORTIFY_SOURCE=3D2'' = Important settings: value of $LANG: en_GB.UTF-8 locale-coding-system: utf-8-unix default enable-multibyte-characters: t = Major mode: Summary Minor modes in effect: jabber-activity-mode: t global-diff-hl-mode: t diff-auto-refine-mode: t global-undo-tree-mode: t undo-tree-mode: t show-paren-mode: t savehist-mode: t electric-indent-mode: t global-auto-complete-mode: t google-this-mode: t erc-list-mode: t erc-menu-mode: t erc-autojoin-mode: t erc-ring-mode: t erc-networks-mode: t erc-pcomplete-mode: t erc-track-mode: t erc-track-minor-mode: t erc-match-mode: t erc-button-mode: t erc-fill-mode: t erc-stamp-mode: t erc-netsplit-mode: t erc-irccontrols-mode: t erc-noncommands-mode: t erc-move-to-prompt-mode: t erc-readonly-mode: t yas-global-mode: t tooltip-mode: t mouse-wheel-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t buffer-read-only: t transient-mark-mode: t abbrev-mode: t = Recent input: C-h m C-x C-o C-x C-k q q q C-h m = C-x C-k C-x C-e C-1 s m a M-- C-1 C-=3D s m a = C-x C-o P P q C-=E7 M-x r e p o C-g = M-x r e p o r m b Artur Malabarba From debbugs-submit-bounces@debbugs.gnu.org Sat Nov 16 04:31:38 2013 Received: (at 15907) by debbugs.gnu.org; 16 Nov 2013 09:31:38 +0000 Received: from localhost ([127.0.0.1]:56664 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VhcE5-0000Bh-Pi for submit@debbugs.gnu.org; Sat, 16 Nov 2013 04:31:37 -0500 Received: from mtaout20.012.net.il ([80.179.55.166]:65061) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VhcE2-0000BS-Jx for 15907@debbugs.gnu.org; Sat, 16 Nov 2013 04:31:36 -0500 Received: from conversion-daemon.a-mtaout20.012.net.il by a-mtaout20.012.net.il (HyperSendmail v2007.08) id <0MWC00F00NHYKO00@a-mtaout20.012.net.il> for 15907@debbugs.gnu.org; Sat, 16 Nov 2013 11:31:28 +0200 (IST) Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout20.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0MWC00F82NSFEX50@a-mtaout20.012.net.il>; Sat, 16 Nov 2013 11:31:28 +0200 (IST) Date: Sat, 16 Nov 2013 11:31:16 +0200 From: Eli Zaretskii Subject: Re: bug#15907: 24.3; Emacs crash due to substitute-command-keys and after-change-functions In-reply-to: <20131115.212301.505338034.artur.malabarba@gmail.com> X-012-Sender: halo1@inter.net.il To: Artur Malabarba Message-id: <83siuwhevv.fsf@gnu.org> References: <20131115.212301.505338034.artur.malabarba@gmail.com> X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 15907 Cc: 15907@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Eli Zaretskii List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) > Date: Fri, 15 Nov 2013 21:23:01 +0000 (GMT) > From: Artur Malabarba > > Emacs crashes whenever `substitute-command-keys' is invoked and one of > the functions in `after-change-functions' contains a call similar to > `(format "%s" 1)'. > > To reproduce: > > 1. Start `emacs -Q'; > 2. Evaluate the following two statements: > (add-hook 'after-change-functions (lambda (&rest a) (format "%s" 1))) > (substitute-command-keys "\\{emacs-lisp-mode-map}") > 3. That's it. Emacs crashes. > > The crash doesn't happen if you replace the number 1 with a string or > a symbol, but it does also happen if you replace it with a list. It no longer crashes after changes in trunk revision 115119. > This is most annoying as it causes a crash whenever `describe-mode' is > invoked. Since you didn't show any real-life use cases, I'm not sure that the result is what you wanted, please do check. From debbugs-submit-bounces@debbugs.gnu.org Sat Nov 16 05:30:21 2013 Received: (at 15907-done) by debbugs.gnu.org; 16 Nov 2013 10:30:21 +0000 Received: from localhost ([127.0.0.1]:56726 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vhd8u-0001hq-51 for submit@debbugs.gnu.org; Sat, 16 Nov 2013 05:30:20 -0500 Received: from mtaout22.012.net.il ([80.179.55.172]:57839) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vhd8r-0001hZ-Ad for 15907-done@debbugs.gnu.org; Sat, 16 Nov 2013 05:30:18 -0500 Received: from conversion-daemon.a-mtaout22.012.net.il by a-mtaout22.012.net.il (HyperSendmail v2007.08) id <0MWC00G00QB99T00@a-mtaout22.012.net.il> for 15907-done@debbugs.gnu.org; Sat, 16 Nov 2013 12:29:47 +0200 (IST) Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout22.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0MWC00GYIQHN2H70@a-mtaout22.012.net.il>; Sat, 16 Nov 2013 12:29:47 +0200 (IST) Date: Sat, 16 Nov 2013 12:29:36 +0200 From: Eli Zaretskii Subject: Re: bug#15907: 24.3; Emacs crash due to substitute-command-keys and after-change-functions In-reply-to: <83siuwhevv.fsf@gnu.org> X-012-Sender: halo1@inter.net.il To: bruce.connor.am@gmail.com Message-id: <83r4aghc6n.fsf@gnu.org> References: <20131115.212301.505338034.artur.malabarba@gmail.com> <83siuwhevv.fsf@gnu.org> X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 15907-done Cc: 15907-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Eli Zaretskii List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) > Date: Sat, 16 Nov 2013 11:31:16 +0200 > From: Eli Zaretskii > Cc: 15907@debbugs.gnu.org > > > 1. Start `emacs -Q'; > > 2. Evaluate the following two statements: > > (add-hook 'after-change-functions (lambda (&rest a) (format "%s" 1))) > > (substitute-command-keys "\\{emacs-lisp-mode-map}") > > 3. That's it. Emacs crashes. > > > > The crash doesn't happen if you replace the number 1 with a string or > > a symbol, but it does also happen if you replace it with a list. > > It no longer crashes after changes in trunk revision 115119. > > > This is most annoying as it causes a crash whenever `describe-mode' is > > invoked. > > Since you didn't show any real-life use cases, I'm not sure that the > result is what you wanted, please do check. Actually, I think you will like revision 115120 much better. The underlying problem was that substitute-command-keys sometimes uses an internal buffer, whose changes would trigger your after-change function, which would invoke 'format', which uses the same internal buffer... As I now think I know what was your real-life problem, and it is now fixed, I'm closing this bug report. Feel free to re-open if there are some leftovers. Thanks. From debbugs-submit-bounces@debbugs.gnu.org Sat Nov 16 07:38:21 2013 Received: (at 15907) by debbugs.gnu.org; 16 Nov 2013 12:38:21 +0000 Received: from localhost ([127.0.0.1]:56802 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vhf8m-00068d-Ha for submit@debbugs.gnu.org; Sat, 16 Nov 2013 07:38:21 -0500 Received: from mtaout23.012.net.il ([80.179.55.175]:40890) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vhf8j-00068M-KL for 15907@debbugs.gnu.org; Sat, 16 Nov 2013 07:38:19 -0500 Received: from conversion-daemon.a-mtaout23.012.net.il by a-mtaout23.012.net.il (HyperSendmail v2007.08) id <0MWC00400W3FBK00@a-mtaout23.012.net.il> for 15907@debbugs.gnu.org; Sat, 16 Nov 2013 14:38:10 +0200 (IST) Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout23.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0MWC004IKWFM8Y80@a-mtaout23.012.net.il>; Sat, 16 Nov 2013 14:38:10 +0200 (IST) Date: Sat, 16 Nov 2013 14:37:59 +0200 From: Eli Zaretskii Subject: Re: bug#15907: 24.3; Emacs crash due to substitute-command-keys and after-change-functions In-reply-to: X-012-Sender: halo1@inter.net.il To: bruce.connor.am@gmail.com Message-id: <83mwl4h68o.fsf@gnu.org> References: <20131115.212301.505338034.artur.malabarba@gmail.com> <83siuwhevv.fsf@gnu.org> X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 15907 Cc: 15907@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Eli Zaretskii List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) > Date: Sat, 16 Nov 2013 11:46:21 +0000 > From: Bruce Connor > > The real life use case was that having smart-mode-line active meant emacs > would crash everytime I hit "C-h m". > > However, I patched smart-mode-line with a work around for this yesterday, > so it's not a use case anymore. I just figured "format" was such a basic > function that it was good to report it anyway. You may wish patching your Emacs with the patch below instead. The problem was not in 'format', but in substitute-command-keys, btw. Here's how I fixed that: === modified file 'src/doc.c' --- src/doc.c 2013-08-11 01:30:20 +0000 +++ src/doc.c 2013-11-16 10:20:32 +0000 @@ -850,6 +850,7 @@ Otherwise, return a new string, without /* This is for computing the SHADOWS arg for describe_map_tree. */ Lisp_Object active_maps = Fcurrent_active_maps (Qnil, Qnil); Lisp_Object earlier_maps; + ptrdiff_t count = SPECPDL_INDEX (); changed = 1; strp += 2; /* skip \{ or \< */ @@ -886,6 +887,10 @@ Otherwise, return a new string, without /* Now switch to a temp buffer. */ oldbuf = current_buffer; set_buffer_internal (XBUFFER (Vprin1_to_string_buffer)); + /* This is for an unusual case where some after-change + function uses 'format' or 'prin1' or something else that + will thrash Vprin1_to_string_buffer we are using. */ + specbind (Qinhibit_modification_hooks, Qt); if (NILP (tem)) { @@ -910,6 +915,7 @@ Otherwise, return a new string, without tem = Fbuffer_string (); Ferase_buffer (); set_buffer_internal (oldbuf); + unbind_to (count, Qnil); subst_string: start = SDATA (tem); === modified file 'src/keymap.c' --- src/keymap.c 2013-08-11 01:30:20 +0000 +++ src/keymap.c 2013-11-16 09:24:19 +0000 @@ -3383,9 +3383,12 @@ describe_map (Lisp_Object map, Lisp_Obje if (vect[i].shadowed) { - SET_PT (PT - 1); + ptrdiff_t pt = max (PT - 1, BEG); + + SET_PT (pt); insert_string ("\n (that binding is currently shadowed by another mode)"); - SET_PT (PT + 1); + pt = min (PT + 1, Z); + SET_PT (pt); } } From unknown Fri Aug 15 01:57:24 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 15 Dec 2013 12:24:03 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator