GNU bug report logs - #61298
Emacs 29.0.60: font-lock throws an args-out-of-range error with a long line.

Previous Next

Package: emacs;

Reported by: Alan Mackenzie <acm <at> muc.de>

Date: Sun, 5 Feb 2023 14:55:01 UTC

Severity: normal

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 61298 in the body.
You can then email your comments to 61298 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#61298; Package emacs. (Sun, 05 Feb 2023 14:55:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alan Mackenzie <acm <at> muc.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 05 Feb 2023 14:55:01 GMT) Full text and rfc822 format available.

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

From: Alan Mackenzie <acm <at> muc.de>
To: bug-gnu-emacs <at> gnu.org
Subject: Emacs 29.0.60: font-lock throws an args-out-of-range error with a
 long line.
Date: Sun, 5 Feb 2023 14:54:35 +0000
Hello, Emacs.

This bug is reproducible in both the master branch and release branch as
updated yesterday evening (European time).

To reproduce this bug:
(i) Apply this bug fix to CC Mode, and byte compile the defun (or file),
and make sure it's loaded:


diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 2631c24f8db..9fa727d9e1f 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -5915,19 +5915,21 @@ c-determine-limit
 	(cond
 	 ((> pos start)			; Nothing but literals
 	  base)
-	 ((> base (point-min))
+	 ((and
+	   (> base (point-min))
+	   (> (- base try-size) (point-min))) ; prevent infinite recursion.
 	  (c-determine-limit how-far-back base (* 2 try-size) org-start))
 	 (t base)))
        ((>= count how-far-back)
 	(c-determine-limit-no-macro
-	(+ (car elt) (- count how-far-back))
-	org-start))
+	 (+ (car elt) (- count how-far-back))
+	 org-start))
        ((eq base (point-min))
 	(point-min))
        ((> base (- start try-size)) ; Can only happen if we hit point-min.
 	(c-determine-limit-no-macro
-	(car elt)
-	org-start))
+	 (car elt)
+	 org-start))
        (t
 	(c-determine-limit (- how-far-back count) base (* 2 try-size)
 			   org-start))))))


(ii) M-: (setq backtrace-on-redisplay-error t)
(iii) C-x b temp.cc.  M-x c++-mode.
(iv) Type in the following text:

char foo [] = R"foo(
  )foo"

(v) With point at the end of the first line in temp.cc,
  M-: (insert (make-string 260000 ?y))
  This may take some time to execute.
(vi) C-x 4 b *Redisplay_trace*
The following backtrace will be seen:

Error: args-out-of-range (260028 260028)
  mapbacktrace(#f(compiled-function (evald func args flags) #<bytecode 0xdf8c26265ae87c7>))
  debug-early-backtrace()
  debug-early(error (args-out-of-range 260028 260028))  <===============
  get-text-property(260028 font-lock-multiline)
  font-lock-extend-region-multiline()
  font-lock-default-fontify-region(1 260029 nil)
  c-font-lock-fontify-region(1 1501 nil)
  font-lock-fontify-region(1 1501)
  #f(compiled-function (fun) #<bytecode -0x156eee0f20909c83>)(font-lock-fontify-region)
  run-hook-wrapped(#f(compiled-function (fun) #<bytecode -0x156eee0f20909c83>) font-lock-fontify-region)
  jit-lock--run-functions(1 1501)
  jit-lock-fontify-now(1 1501)
  jit-lock-function(1)
  redisplay_internal\ \(C\ function\)()

This is clearly a bug.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Position 260028 is within the bounds of the buffer.  It would appear
that the new-ish long-lines code has narrowed the buffer at some stage
such that point-max is less than the end of the buffer.  I propose the
following simple patch which fixes (or works around) this bug:

diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index 1fa45379b9f..9e944fe188a 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -1154,6 +1154,8 @@ font-lock-default-fontify-region
   "Fontify the text between BEG and END.
 If LOUDLY is non-nil, print status messages while fontifying.
 This function is the default `font-lock-fontify-region-function'."
+  (or (<= end (point-max))
+      (setq end (point-max)))
   (with-silent-modifications
    ;; Use the fontification syntax table, if any.
    (with-syntax-table (or font-lock-syntax-table (syntax-table))


-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61298; Package emacs. (Sun, 05 Feb 2023 15:13:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 61298 <at> debbugs.gnu.org
Subject: Re: bug#61298: Emacs 29.0.60: font-lock throws an args-out-of-range
 error with a long line.
Date: Sun, 05 Feb 2023 17:12:42 +0200
> Date: Sun, 5 Feb 2023 14:54:35 +0000
> From: Alan Mackenzie <acm <at> muc.de>
> 
> Error: args-out-of-range (260028 260028)
>   mapbacktrace(#f(compiled-function (evald func args flags) #<bytecode 0xdf8c26265ae87c7>))
>   debug-early-backtrace()
>   debug-early(error (args-out-of-range 260028 260028))  <===============
>   get-text-property(260028 font-lock-multiline)
>   font-lock-extend-region-multiline()
>   font-lock-default-fontify-region(1 260029 nil)
>   c-font-lock-fontify-region(1 1501 nil)
>   font-lock-fontify-region(1 1501)
>   #f(compiled-function (fun) #<bytecode -0x156eee0f20909c83>)(font-lock-fontify-region)
>   run-hook-wrapped(#f(compiled-function (fun) #<bytecode -0x156eee0f20909c83>) font-lock-fontify-region)
>   jit-lock--run-functions(1 1501)
>   jit-lock-fontify-now(1 1501)
>   jit-lock-function(1)
>   redisplay_internal\ \(C\ function\)()
> 
> This is clearly a bug.
> 
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> 
> Position 260028 is within the bounds of the buffer.  It would appear
> that the new-ish long-lines code has narrowed the buffer at some stage
> such that point-max is less than the end of the buffer.  I propose the
> following simple patch which fixes (or works around) this bug:

Fine with me, please install on the emacs-29 branch, and thanks.




Reply sent to Alan Mackenzie <acm <at> muc.de>:
You have taken responsibility. (Sun, 05 Feb 2023 16:05:01 GMT) Full text and rfc822 format available.

Notification sent to Alan Mackenzie <acm <at> muc.de>:
bug acknowledged by developer. (Sun, 05 Feb 2023 16:05:01 GMT) Full text and rfc822 format available.

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

From: Alan Mackenzie <acm <at> muc.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 61298-done <at> debbugs.gnu.org
Subject: Re: bug#61298: Emacs 29.0.60: font-lock throws an args-out-of-range
 error with a long line.
Date: Sun, 5 Feb 2023 16:04:05 +0000
Hello, Eli.

On Sun, Feb 05, 2023 at 17:12:42 +0200, Eli Zaretskii wrote:
> > Date: Sun, 5 Feb 2023 14:54:35 +0000
> > From: Alan Mackenzie <acm <at> muc.de>

> > Error: args-out-of-range (260028 260028)
> >   mapbacktrace(#f(compiled-function (evald func args flags) #<bytecode 0xdf8c26265ae87c7>))
> >   debug-early-backtrace()
> >   debug-early(error (args-out-of-range 260028 260028))  <===============
> >   get-text-property(260028 font-lock-multiline)
> >   font-lock-extend-region-multiline()
> >   font-lock-default-fontify-region(1 260029 nil)
> >   c-font-lock-fontify-region(1 1501 nil)
> >   font-lock-fontify-region(1 1501)
> >   #f(compiled-function (fun) #<bytecode -0x156eee0f20909c83>)(font-lock-fontify-region)
> >   run-hook-wrapped(#f(compiled-function (fun) #<bytecode -0x156eee0f20909c83>) font-lock-fontify-region)
> >   jit-lock--run-functions(1 1501)
> >   jit-lock-fontify-now(1 1501)
> >   jit-lock-function(1)
> >   redisplay_internal\ \(C\ function\)()

> > This is clearly a bug.

> > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

> > Position 260028 is within the bounds of the buffer.  It would appear
> > that the new-ish long-lines code has narrowed the buffer at some stage
> > such that point-max is less than the end of the buffer.  I propose the
> > following simple patch which fixes (or works around) this bug:

> Fine with me, please install on the emacs-29 branch, and thanks.

I have done so, and I'm closing the bug with this post.

Thanks for such a rapid response.

-- 
Alan Mackenzie (Nuremberg, Germany).




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 06 Mar 2023 12:24:11 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 23 days ago.

Previous Next


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