all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@gmail.com>
To: 36897@debbugs.gnu.org
Subject: bug#36897: 27.0.50; [CC Mode] c-after-change may signal error in narrowed buffer
Date: Thu, 01 Aug 2019 20:30:17 -0400	[thread overview]
Message-ID: <87d0hotnmu.fsf@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1011 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 1544 bytes --]

From 2865541594f18898c234a2ed076879ce2f887693 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@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


[-- Attachment #3: Type: text/plain, Size: 483 bytes --]



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


             reply	other threads:[~2019-08-02  0:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-02  0:30 Noam Postavsky [this message]
     [not found] ` <mailman.507.1564705872.1985.bug-gnu-emacs@gnu.org>
2019-08-02  8:41   ` bug#36897: 27.0.50; [CC Mode] c-after-change may signal error in narrowed buffer Alan Mackenzie
     [not found] ` <mailman.530.1564738445.1985.bug-gnu-emacs@gnu.org>
2019-08-02 10:41   ` Alan Mackenzie
2019-08-02 11:40     ` Noam Postavsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d0hotnmu.fsf@gmail.com \
    --to=npostavs@gmail.com \
    --cc=36897@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.