From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#40317: 27.0.90; Reverting a buffer that visits C file signals an error Date: Fri, 18 Sep 2020 20:13:35 +0000 Message-ID: <20200918201335.GE5497@ACM> References: <87k0wtmvod.fsf@cassou.me> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32783"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Damien Cassou , 40317@debbugs.gnu.org To: Jeff Norden Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 18 22:21:40 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 1kJMt0-0008PA-4Z for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 18 Sep 2020 22:21:38 +0200 Original-Received: from localhost ([::1]:47390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kJMsz-0003gM-5B for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 18 Sep 2020 16:21:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kJMle-0005oR-M7 for bug-gnu-emacs@gnu.org; Fri, 18 Sep 2020 16:14:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:32974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kJMle-0001ns-By for bug-gnu-emacs@gnu.org; Fri, 18 Sep 2020 16:14:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kJMle-0005ef-7Z for bug-gnu-emacs@gnu.org; Fri, 18 Sep 2020 16:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 18 Sep 2020 20:14: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.160046002521705 (code B ref 40317); Fri, 18 Sep 2020 20:14:02 +0000 Original-Received: (at 40317) by debbugs.gnu.org; 18 Sep 2020 20:13:45 +0000 Original-Received: from localhost ([127.0.0.1]:44520 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kJMlM-0005e1-Tp for submit@debbugs.gnu.org; Fri, 18 Sep 2020 16:13:45 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:13263 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1kJMlK-0005dm-Rh for 40317@debbugs.gnu.org; Fri, 18 Sep 2020 16:13:43 -0400 Original-Received: (qmail 41512 invoked by uid 3782); 18 Sep 2020 20:13:36 -0000 Original-Received: from acm.muc.de (p4fe15d0a.dip0.t-ipconnect.de [79.225.93.10]) by localhost.muc.de (tmda-ofmipd) with ESMTP; Fri, 18 Sep 2020 22:13:35 +0200 Original-Received: (qmail 1017 invoked by uid 1000); 18 Sep 2020 20:13:35 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de 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:188352 Archived-At: Hello, Jeff. Thanks for contributing towards this bug. On Thu, Sep 17, 2020 at 20:21:47 -0500, Jeff Norden wrote: > 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. [ .... ] > 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 I've spent quite a long time looking at this, trying various means to trigger the error (via `insert-file-contents' and `revert-buffer'). Then it suddenly dawned on me that the (setq c-new-END (.....)) is OK. If the body of the the last `unless' has been run, (- end beg) and old-len are equal to each other, and to the buffer length. So c-new-END doesn't get changed in this case. Of course, it's hopelessly confusing coding. It seems to have confused you, and it certainly confused me, even though I wrote it myself only a short while ago. If that code is to remain as it is, it definitely needs commenting. There seems to be an aesthetic benefit in keeping the (setq c-new-BEG ...) separate from the ~13 line section which deals with the out-of-sequence calling of before-change-functions and after-change-functions. But I'll sleep on that thought. [ .... ] > Hope this helps, > -Jeff Yes, it has helped, thanks. -- Alan Mackenzie (Nuremberg, Germany).