diff --git a/src/cmds.c b/src/cmds.c index 99e436e65c1..e9dee5ed2e3 100644 --- a/src/cmds.c +++ b/src/cmds.c @@ -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; diff --git a/test/src/cmds-tests.el b/test/src/cmds-tests.el index a02c36868ca..8c0e4706e3c 100644 --- a/test/src/cmds-tests.el +++ b/test/src/cmds-tests.el @@ -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