From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jeff Norden Newsgroups: gmane.emacs.bugs Subject: bug#40317: 27.0.90; Reverting a buffer that visits C file signals an error Date: Thu, 17 Sep 2020 20:21:47 -0500 Message-ID: References: <83k1335m2e.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36189"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Damien Cassou , Alan Mackenzie To: 40317@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 18 04:16:11 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kJ5wY-0009Iq-QW for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 18 Sep 2020 04:16:10 +0200 Original-Received: from localhost ([::1]:56352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kJ5wX-0001fe-FS for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 17 Sep 2020 22:16:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33076) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kJ5wQ-0001fU-Mp for bug-gnu-emacs@gnu.org; Thu, 17 Sep 2020 22:16:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56888) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kJ5wQ-0008Ns-DP for bug-gnu-emacs@gnu.org; Thu, 17 Sep 2020 22:16:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kJ5wQ-0003sg-9t for bug-gnu-emacs@gnu.org; Thu, 17 Sep 2020 22:16:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jeff Norden Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 18 Sep 2020 02:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40317 X-GNU-PR-Package: emacs Original-Received: via spool by 40317-submit@debbugs.gnu.org id=B40317.160039531814859 (code B ref 40317); Fri, 18 Sep 2020 02:16:02 +0000 Original-Received: (at 40317) by debbugs.gnu.org; 18 Sep 2020 02:15:18 +0000 Original-Received: from localhost ([127.0.0.1]:40201 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kJ5vg-0003rX-Il for submit@debbugs.gnu.org; Thu, 17 Sep 2020 22:15:18 -0400 Original-Received: from mta.tntech.edu ([149.149.2.87]:45987) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kJ560-0002WP-1B for 40317@debbugs.gnu.org; Thu, 17 Sep 2020 21:21:52 -0400 Original-Received: from math.tntech.edu (unknown [149.149.102.6]) by mta.tntech.edu (Postfix) with ESMTPS id A8F1C3000D90; Thu, 17 Sep 2020 20:21:49 -0500 (CDT) Original-Received: from norden.tntech.edu ([149.149.102.4] helo=norden.math.tntech.edu) by math.tntech.edu with esmtp (Exim 4.92) (envelope-from ) id 1kJ55v-0007Bb-5m; Thu, 17 Sep 2020 20:21:47 -0500 Original-Received: by norden.math.tntech.edu (Postfix, from userid 742) id 2365A2572B73; Thu, 17 Sep 2020 20:21:47 -0500 (CDT) In-Reply-To: <87k0wtmvod.fsf@cassou.me> (message from Damien Cassou on Wed, 16 Sep 2020 20:19:14 +0200) X-SA-Spam-Score: 0.0 X-SA-Spam-Report: Spam detection software, running on the system "math.tntech.edu", has NOT identified this incoming email as spam. If you have any questions, contact @@CONTACT_ADDRESS@@ pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_HELO_TEMPERROR SPF: test of HELO record failed (temperror) X-Mailman-Approved-At: Thu, 17 Sep 2020 22:15:15 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:188263 Archived-At: I came across this by searching for args-out-of-range bugs. I recently found a bug in forward-comment (which I'll post separately) that was causing out-of-range errors for me, and I wondered if forward-comment might be relevant to other issues. It isn't in this case, but I think I did find the source of the problem. The function c-after-change (in cc-mode.el) was changed between 26.3 and 27.1, to handle more cases where the before and/or after change functions get called multiple times. The function now begins (line numbers are from the current master version) with: 1993 ;; Note: c-just-done-before-change is nil, t, or 'whole-buffer. 1994 (unless (c-called-from-text-property-change-p) 1995 (save-restriction 1996 (widen) 1997 (unless c-just-done-before-change 1998 (c-before-change (point-min) (point-max))) 1999 (unless (eq c-just-done-before-change t) 2000 (setq beg (point-min) 2001 end (point-max) 2002 old-len (- end beg) 2003 c-new-BEG (point-min) 2004 c-new-END (point-max))) 2005 (setq c-just-done-before-change nil))) 2006 2007 ;; (c-new-BEG c-new-END) will be the region to fontify. It may become 2008 ;; larger than (beg end). 2009 (setq c-new-END (- (+ c-new-END (- end beg)) old-len)) It looks like it is now possible for the last line above, which increments c-new-END, to run even if c-new-END has been set to the after-change value of point-max. That will make c-new-END point past the end of the buffer. --- In the backtrace from March, > c-after-change(214738 215088 0) indicates that 350 bytes have been added to the buffer, although not at end. If point-max was 216785 (which would be the value if the buffer-length was actually 216784), then line-2009 would set c-new-END to 216785+350 = 217135, which would then be used by c-after-change-mark-abnormal-strings when calling parse-partial-sexp. This fits the args-out-of-range error in the backtrace. --- A simple fix would be to change line-2009 to (setq c-new-END (min (- (+ c-new-END (- end beg)) old-len) (point-max))) But, maybe the third 'unless' could be changed to 'if' instead, with the increment as the else. I don't know if c-new-END might need to be incremented when c-called-from-text-property-change-p is true. Unfortunately, I can't figure out how to trigger this bug myself. If you want to be 100% sure about it, you might try adding (if (> c-new-END (point-max)) (error "c-new-END is too big! %d > %d" c-new-END (point-max))) right after line-2009 and see if it raises an error before it gets to parse-partial-sexp. Hope this helps, -Jeff