Subject: bug#51171: 27.2; `forward-word' w/arg bug in narrowed buffer

From: Lars Ingebrigtsen <[email-masked]>
Date: Mon, 12 Sep 2022 14:02:03 +0200

Eli Zaretskii <[email-masked]> writes:

>> To reproduce from 'emacs -Q /path/to/dcl.c’ (file attached):
>>    1. M-x `subword-mode' (side question: should C-c C-w still use the
>>       obsolete alias `c-subword-mode'?).
>>    2. Navigate to the function 'int dirdcl(void)' and use
>>       `narrow-to-defun' (C-x n d).
>>    3. From the top of the buffer, use `forward-word' with an arg greater
>>       than 1 (like C-u 2 M-f).
>>    4. Repeat this with C-x z z z z... until you get an error around the
>>       start of the while loop (2nd to last message in list below).
>>    5. Moving point forward then trying the same command again will yield
>>        the last message with a number greater than `point-max' (5741).
>> 
>> Other notes:
>>       - The bug dissapears with a widened buffer or when narrowing to
>>         earlier functions.
>>       - `backward-word’ doesn’t seem to have the same problem.
>>       - I'm reporting this from OSX 10.14.6 (homebrew), but it also occurs on
>>         Arch Linux (emacs being installed from the standard pacman repos).
>
> Stefan, any suggestions wrt this?

The backtrace is:

Debugger entered--Lisp error: (error "Error in syntax_table logic for to-the-end interva...")
  forward-word(2)
  funcall-interactively(forward-word 2)
  call-interactively(forward-word nil nil)

Slightly easier recipe:

Open that file, `M-x subword-mode', and then navigate to

    while (gettoken() == PARENS || TokenType == BRACKETS) {

`C-x n d', put point after BRACKETS and then say `M-2 M-f'.  Then you
get that error message.

Just `M-f' works fine.

I tried to narrow this down to a simpler file, but I was unable to -- it
seems like the error depends on lots of state in that specific file.