summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2019-10-30 14:40:06 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2019-10-30 14:43:14 -0700
commitf2a72bb8ed29223dd1197492d4270c171db5e443 (patch)
tree60d90f60474f34750bf6c95b356c6128529cb1a4 /test
parent581601e650cc8bdcf3ed83c6ae36744601c12ce9 (diff)
downloademacs-f2a72bb8ed29223dd1197492d4270c171db5e443.tar.gz
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')
-rw-r--r--test/src/print-tests.el6
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."
;; Bug#31146.
(let ((x '(0 . #1=(0 . #1#))))
(let ((print-circle nil))
- (should (string-match "\\`(0 0 . #[0-9])\\'"
+ (should (string-match "\\`(0\\( 0\\)* . #[0-9]+)\\'"
(print-tests--prin1-to-string x))))
(let ((print-circle t))
(should (equal "(0 . #1=(0 . #1#))" (print-tests--prin1-to-string x))))))
+(print-tests--deftest error-message-string-circular ()
+ (let ((err (list 'error)))
+ (setcdr err err)
+ (should-error (error-message-string err) :type 'circular-list)))
(provide 'print-tests)
;;; print-tests.el ends here