GNU bug report logs - #36897
27.0.50; [CC Mode] c-after-change may signal error in narrowed buffer

Previous Next

Package: emacs;

Reported by: Noam Postavsky <npostavs <at> gmail.com>

Date: Fri, 2 Aug 2019 00:31:01 UTC

Severity: normal

Tags: fixed

Merged with 36898

Found in version 27.0.50

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 36897 in the body.
You can then email your comments to 36897 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#36897; Package emacs, cc-mode. (Fri, 02 Aug 2019 00:31:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Noam Postavsky <npostavs <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org. (Fri, 02 Aug 2019 00:31:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 27.0.50; [CC Mode] c-after-change may signal error in narrowed buffer
Date: Thu, 01 Aug 2019 20:30:17 -0400
[Message part 1 (text/plain, inline)]
Package: emacs, cc-mode

From 'emacs -Q', eval the following:

(with-current-buffer (get-buffer-create "*test*")
  (erase-buffer)
  (insert "int main()\n{\n  \n}\n")
  (search-backward "\n}")
  (c-mode)
  (save-restriction
    (narrow-to-region (point) (point))
    (insert "foo")))

Gives the backtrace:

Debugger entered--Lisp error: (args-out-of-range 1 1)
  get-text-property(1 c-fl-syn-tab)
  c-clear-string-fences()
  #f(compiled-function () #<bytecode 0xbb39fd>)()
  c-after-change(16 19 0)
  insert("foo")
  (save-restriction (narrow-to-region (point) (point)) (insert "foo"))
  (save-current-buffer (set-buffer (get-buffer-create "*test*")) (erase-buffer) (insert "int main()\n{\n  \n}\n") (search-backward "\n}") (c-mode) (save-restriction (narrow-to-region (point) (point)) (insert "foo")))

This is a reduced test case from
https://github.com/joaotavora/eglot/issues/291.

I think the obvious fix is to extend the save-restriction just a bit
further to cover c-clear-string-fences, patch attached.

[0001-Fix-c-after-change-in-narrowed-buffer.patch (text/x-diff, inline)]
From 2865541594f18898c234a2ed076879ce2f887693 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Thu, 1 Aug 2019 20:14:32 -0400
Subject: [PATCH] Fix c-after-change in narrowed buffer

* lisp/progmodes/cc-mode.el (c-after-change): Include the
c-clear-string-fences call in the save-restriction, so that it has
access to the widened buffer.
---
 lisp/progmodes/cc-mode.el | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index a5e158933b..9df4224448 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -1989,10 +1989,10 @@ c-after-change
       ;; When `combine-after-change-calls' is used we might get calls
       ;; with regions outside the current narrowing.  This has been
       ;; observed in Emacs 20.7.
-      (unwind-protect
-	  (progn
-	    (c-restore-string-fences (point-min) (point-max))
-	    (save-restriction
+      (save-restriction
+	(unwind-protect
+	    (progn
+	      (c-restore-string-fences (point-min) (point-max))
 	      (save-match-data ; c-recognize-<>-arglists changes match-data
 		(widen)
 
@@ -2032,8 +2032,8 @@ c-after-change
 		(save-excursion
 		  (mapc (lambda (fn)
 			  (funcall fn beg end old-len))
-			c-before-font-lock-functions)))))
-	(c-clear-string-fences))))
+			c-before-font-lock-functions))))
+	  (c-clear-string-fences)))))
   ;; A workaround for syntax-ppss's failure to notice syntax-table text
   ;; property changes.
   (when (fboundp 'syntax-ppss)
-- 
2.11.0

[Message part 3 (text/plain, inline)]

In GNU Emacs 27.0.50 (build 23, x86_64-pc-linux-gnu, X toolkit, Xaw scroll bars)
 of 2019-07-30 built on minid
Repository revision: 3a59cc84069376802ba8fd731b524d78db58262c
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.11902000
System Description: Debian GNU/Linux 9 (stretch)

Recent messages:
Error during redisplay: (jit-lock-function 18) signaled (args-out-of-range 1 1)
Continuing.
c-clear-string-fences: Args out of range: 1, 1


Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#36897; Package emacs, cc-mode. (Fri, 02 Aug 2019 09:34:02 GMT) Full text and rfc822 format available.

Message #8 received at 36897 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 36897 <at> debbugs.gnu.org
Subject: Re: bug#36897: 27.0.50;
 [CC Mode] c-after-change may signal error in narrowed buffer
Date: 2 Aug 2019 08:41:21 -0000
Hello, Noam.

In article <mailman.507.1564705872.1985.bug-gnu-emacs <at> gnu.org> you wrote:
> [-- text/plain, encoding 7bit, charset: US-ASCII, 31 lines --]

> Package: emacs, cc-mode

>>From 'emacs -Q', eval the following:

> (with-current-buffer (get-buffer-create "*test*")
>   (erase-buffer)
>   (insert "int main()\n{\n  \n}\n")
>   (search-backward "\n}")
>   (c-mode)
>   (save-restriction
>     (narrow-to-region (point) (point))
>     (insert "foo")))

> Gives the backtrace:

> Debugger entered--Lisp error: (args-out-of-range 1 1)
>   get-text-property(1 c-fl-syn-tab)
>   c-clear-string-fences()
>   #f(compiled-function () #<bytecode 0xbb39fd>)()
>   c-after-change(16 19 0)
>   insert("foo")
>   (save-restriction (narrow-to-region (point) (point)) (insert "foo"))
>   (save-current-buffer (set-buffer (get-buffer-create "*test*")) (erase-buffer) (insert "int main()\n{\n  \n}\n") (search-backward "\n}") (c-mode) (save-restriction (narrow-to-region (point) (point)) (insert "foo")))

Yes, thanks.  I've known about this for around a week, and I have a patch
for it prepared.  I was just giving the OP who reported it to me an extra
day or two to comment on it.

> This is a reduced test case from
> https://github.com/joaotavora/eglot/issues/291.

> I think the obvious fix is to extend the save-restriction just a bit
> further to cover c-clear-string-fences, patch attached.

Yes.  The "same" problem also happened in c-before-change, and my patch
fixes that, too.  (Otherwise, it's pretty much the same as your patch, as
far as c-after-change is concerned.)

I'll commit my patch soon, hopefully today.

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).





Reply sent to Alan Mackenzie <acm <at> muc.de>:
You have taken responsibility. (Fri, 02 Aug 2019 11:35:02 GMT) Full text and rfc822 format available.

Notification sent to Noam Postavsky <npostavs <at> gmail.com>:
bug acknowledged by developer. (Fri, 02 Aug 2019 11:35:02 GMT) Full text and rfc822 format available.

Message #13 received at 36897-done <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 36897-done <at> debbugs.gnu.org
Subject: Re: bug#36897: 27.0.50;
 [CC Mode] c-after-change may signal error in narrowed buffer
Date: 2 Aug 2019 10:41:28 -0000
In article <mailman.530.1564738445.1985.bug-gnu-emacs <at> gnu.org> I wrote:

[ .... ]

> I'll commit my patch soon, hopefully today.

I've done this, and I'm closing the bug.

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).





Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#36897; Package emacs, cc-mode. (Fri, 02 Aug 2019 11:41:01 GMT) Full text and rfc822 format available.

Message #16 received at 36897 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 36897 <at> debbugs.gnu.org
Subject: Re: bug#36897: 27.0.50; [CC Mode] c-after-change may signal error in
 narrowed buffer
Date: Fri, 2 Aug 2019 07:40:11 -0400
On Fri, 2 Aug 2019 at 07:34, Alan Mackenzie <acm <at> muc.de> wrote:

> > I'll commit my patch soon, hopefully today.
>
> I've done this, and I'm closing the bug.

Thanks, works here.




Added tag(s) fixed. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 02 Aug 2019 11:42:02 GMT) Full text and rfc822 format available.

bug reassigned from package 'emacs, cc-mode' to 'emacs'. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 02 Aug 2019 20:11:01 GMT) Full text and rfc822 format available.

bug No longer marked as found in versions 27.0.50. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 02 Aug 2019 20:11:01 GMT) Full text and rfc822 format available.

Forcibly Merged 36897 36898. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 02 Aug 2019 20:11:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 31 Aug 2019 11:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 11 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.