diff options
| author | Paul Eggert | 2019-10-30 14:40:06 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-10-30 14:43:14 -0700 |
| commit | f2a72bb8ed29223dd1197492d4270c171db5e443 (patch) | |
| tree | 60d90f60474f34750bf6c95b356c6128529cb1a4 /test/src | |
| parent | 581601e650cc8bdcf3ed83c6ae36744601c12ce9 (diff) | |
| download | emacs-f2a72bb8ed29223dd1197492d4270c171db5e443.tar.gz emacs-f2a72bb8ed29223dd1197492d4270c171db5e443.zip | |
Fix print.c infloop on circular lists
Fix infinite loops in print.c when a circular list is passed
to command-error-default-function or to error-message-string.
* src/print.c (print_error_message):
Use FOR_EACH_TAIL to avoid infloop on circular lists.
(print_object): Use FOR_EACH_TAIL_SAFE, as it uses
Brent’s teleporting tortoise-hare algorithm which is
asymptotically better than the classic tortoise-hare
algorithm that the code wsas using.
* test/src/print-tests.el (print-circle-2): When print-circle
is nil, do not insist on a particular cycle-detection heuristic.
(error-message-string-circular): New test.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/print-tests.el | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/test/src/print-tests.el b/test/src/print-tests.el index 26d49a5ffba..77371a1b4ce 100644 --- a/test/src/print-tests.el +++ b/test/src/print-tests.el | |||
| @@ -345,11 +345,15 @@ otherwise, use a different charset." | |||
| 345 | ;; Bug#31146. | 345 | ;; Bug#31146. |
| 346 | (let ((x '(0 . #1=(0 . #1#)))) | 346 | (let ((x '(0 . #1=(0 . #1#)))) |
| 347 | (let ((print-circle nil)) | 347 | (let ((print-circle nil)) |
| 348 | (should (string-match "\\`(0 0 . #[0-9])\\'" | 348 | (should (string-match "\\`(0\\( 0\\)* . #[0-9]+)\\'" |
| 349 | (print-tests--prin1-to-string x)))) | 349 | (print-tests--prin1-to-string x)))) |
| 350 | (let ((print-circle t)) | 350 | (let ((print-circle t)) |
| 351 | (should (equal "(0 . #1=(0 . #1#))" (print-tests--prin1-to-string x)))))) | 351 | (should (equal "(0 . #1=(0 . #1#))" (print-tests--prin1-to-string x)))))) |
| 352 | 352 | ||
| 353 | (print-tests--deftest error-message-string-circular () | ||
| 354 | (let ((err (list 'error))) | ||
| 355 | (setcdr err err) | ||
| 356 | (should-error (error-message-string err) :type 'circular-list))) | ||
| 353 | 357 | ||
| 354 | (provide 'print-tests) | 358 | (provide 'print-tests) |
| 355 | ;;; print-tests.el ends here | 359 | ;;; print-tests.el ends here |