unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: 61298@debbugs.gnu.org
Subject: bug#61298: 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	[thread overview]
Message-ID: <Y9/DKw7UdwcJPUU9@ACM> (raw)

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





             reply	other threads:[~2023-02-05 14:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-05 14:54 Alan Mackenzie [this message]
2023-02-05 15:12 ` bug#61298: Emacs 29.0.60: font-lock throws an args-out-of-range error with a long line Eli Zaretskii
2023-02-05 16:04   ` Alan Mackenzie

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=Y9/DKw7UdwcJPUU9@ACM \
    --to=acm@muc.de \
    --cc=61298@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 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).