Avoid crash in self-insert-command for peculiar arguments

* src/cmds.c (internal_self_insert): Don't call auto-fill-function
after inserting zero newlines.
* test/src/cmds-tests.el (self-insert-zero-newlines): New.
This commit is contained in:
Pip Cet 2026-05-24 11:51:38 +00:00
parent 94dbab2fe4
commit 7f8ac8bf6f
2 changed files with 10 additions and 1 deletions

View file

@ -477,7 +477,8 @@ internal_self_insert (int c, EMACS_INT n)
if ((CHAR_TABLE_P (Vauto_fill_chars)
? !NILP (CHAR_TABLE_REF (Vauto_fill_chars, c))
: (c == ' ' || c == '\n'))
&& !NILP (BVAR (current_buffer, auto_fill_function)))
&& !NILP (BVAR (current_buffer, auto_fill_function))
&& n > 0)
{
Lisp_Object auto_fill_result;

View file

@ -40,5 +40,13 @@
(let ((shortage (forward-line (+ 2 most-positive-fixnum))))
(should (= shortage (1+ most-positive-fixnum))))))
(ert-deftest self-insert-zero-newlines ()
"Test `self-insert-command' with arguments which used to cause a crash."
(with-temp-buffer
(let* ((pt nil)
(auto-fill-function (lambda () (setq pt (point)))))
(self-insert-command 0 10)
(should-not (equal pt 0)))))
(provide 'cmds-tests)
;;; cmds-tests.el ends here