unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#61298: Emacs 29.0.60: font-lock throws an args-out-of-range error with a long line.
@ 2023-02-05 14:54 Alan Mackenzie
  2023-02-05 15:12 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Mackenzie @ 2023-02-05 14:54 UTC (permalink / raw)
  To: 61298

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).





^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#61298: Emacs 29.0.60: font-lock throws an args-out-of-range error with a long line.
  2023-02-05 14:54 bug#61298: Emacs 29.0.60: font-lock throws an args-out-of-range error with a long line Alan Mackenzie
@ 2023-02-05 15:12 ` Eli Zaretskii
  2023-02-05 16:04   ` Alan Mackenzie
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2023-02-05 15:12 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 61298

> Date: Sun, 5 Feb 2023 14:54:35 +0000
> From: Alan Mackenzie <acm@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.





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#61298: Emacs 29.0.60: font-lock throws an args-out-of-range error with a long line.
  2023-02-05 15:12 ` Eli Zaretskii
@ 2023-02-05 16:04   ` Alan Mackenzie
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Mackenzie @ 2023-02-05 16:04 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 61298-done

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@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).





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-05 16:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-05 14:54 bug#61298: Emacs 29.0.60: font-lock throws an args-out-of-range error with a long line Alan Mackenzie
2023-02-05 15:12 ` Eli Zaretskii
2023-02-05 16:04   ` Alan Mackenzie

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).