Subject: bug#61215: 29.0.60; font-lock broken in diff-mode with long lines

From: Juri Linkov <[email-masked]>
Date: Thu, 02 Feb 2023 19:16:34 +0200

>> >> when there is at least one long line near the end of
>> >> a diff-mode buffer, then sometimes the buffer gets truncated,
>> >> 'diff-hunk-file-names' returns nil on diff headings,
>> >> and there are a lot of such errors in the Messages buffer:
>> >>
>> >>   Error during redisplay: (jit-lock-function 1) signaled (args-out-of-range #<buffer *vc-diff*> 1118 1370)
>> >
>> > We can and should fix this and other problems, but only if they are
>> > reported.  Would you please file a bug report for any such problem you
>> > find?
>>
>> This is a new bug report created from bug#56682.
>
> Thanks.  Can you post a recipe for reproducing that, preferably
> starting from "emacs -Q"?

0. emacs -Q
1. Set debug-on-error and backtrace-on-redisplay-error to t
2. Create a commit with some diff hunks in a prog mode at the beginning,
   and a single-line 1MB file added at the end;
3. From *vc-change-log* type `d' on that commit that opens *vc-diff* buffer
4. Scroll the *vc-diff* buffer

It displays an error in the *Warning* buffer:

  ⛔ Warning (error): Error in a redisplay Lisp hook.  See buffer *Redisplay_trace*

And *Redisplay_trace* contains:

Error: args-out-of-range (#<buffer *vc-diff*> 2000 251555)
  mapbacktrace(#f(compiled-function (evald func args flags) #<bytecode 0x177cfe2073ae86a5>))
  debug-early-backtrace()
  debug-early(error (args-out-of-range #<buffer *vc-diff*> 2000 251555))
  buffer-substring-no-properties(2000 251555)
  diff-syntax-fontify-hunk(2000 251555 nil)
  diff-syntax-fontify(2000 251555)
  #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_39>(2000 251555)
  diff--iterate-hunks(10000 #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_39>)
  diff--font-lock-syntax(10000)
  font-lock-fontify-keywords-region(1527 10000 nil)
  font-lock-default-fontify-region(1527 3027 nil)
  font-lock-fontify-region(1527 3027)
  #f(compiled-function (fun) #<bytecode -0x156e6c38c061f903>)(font-lock-fontify-region)
  run-hook-wrapped(#f(compiled-function (fun) #<bytecode -0x156e6c38c061f903>) font-lock-fontify-region)
  jit-lock--run-functions(1527 3027)
  jit-lock-fontify-now(1527 3027)
  jit-lock-function(1527)
  redisplay_internal\ \(C\ function\)()