diff options
| author | Mattias EngdegÄrd | 2022-03-26 16:44:18 +0100 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2022-03-26 17:11:40 +0100 |
| commit | 2dfeea8962751718168494c0560d69e678794b39 (patch) | |
| tree | feb733329b75e74f0e3569706a0d17f3dcc79022 /test/src/lread-tests.el | |
| parent | e96061de95d053a4c5e303c7f75e0e928e474938 (diff) | |
| download | emacs-2dfeea8962751718168494c0560d69e678794b39.tar.gz emacs-2dfeea8962751718168494c0560d69e678794b39.zip | |
Fix reader infinite recursion for circular mixed-type values
Make sure that the value added to the `read_objects_completed` set is
the one we actually return; previously this wasn't the case for conses
because of an optimisation (bug#54501).
Also add a check for vacuous self-references such as #1=#1# instead of
returning a nonsense value from thin air.
* src/lread.c (read1): Treat numbered conses correctly as described
above. Detect vacuous self-references.
* test/src/lread-tests.el (lread-test-read-and-print)
(lread-test-circle-cases, lread-circle): Add tests.
Diffstat (limited to 'test/src/lread-tests.el')
| -rw-r--r-- | test/src/lread-tests.el | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el index 862f6a6595f..9ec54c719c8 100644 --- a/test/src/lread-tests.el +++ b/test/src/lread-tests.el | |||
| @@ -258,5 +258,27 @@ literals (Bug#20852)." | |||
| 258 | (should (equal (read "-0.e-5") -0.0)) | 258 | (should (equal (read "-0.e-5") -0.0)) |
| 259 | ) | 259 | ) |
| 260 | 260 | ||
| 261 | (defun lread-test-read-and-print (str) | ||
| 262 | (let* ((read-circle t) | ||
| 263 | (print-circle t) | ||
| 264 | (val (read-from-string str))) | ||
| 265 | (if (consp val) | ||
| 266 | (prin1-to-string (car val)) | ||
| 267 | (error "reading %S failed: %S" str val)))) | ||
| 268 | |||
| 269 | (defconst lread-test-circle-cases | ||
| 270 | '("#1=(#1# . #1#)" | ||
| 271 | "#1=[#1# a #1#]" | ||
| 272 | "#1=(#2=[#1# #2#] . #1#)" | ||
| 273 | "#1=(#2=[#1# #2#] . #2#)" | ||
| 274 | "#1=[#2=(#1# . #2#)]" | ||
| 275 | "#1=(#2=[#3=(#1# . #2#) #4=(#3# . #4#)])" | ||
| 276 | )) | ||
| 277 | |||
| 278 | (ert-deftest lread-circle () | ||
| 279 | (dolist (str lread-test-circle-cases) | ||
| 280 | (ert-info (str :prefix "input: ") | ||
| 281 | (should (equal (lread-test-read-and-print str) str)))) | ||
| 282 | (should-error (read-from-string "#1=#1#") :type 'invalid-read-syntax)) | ||
| 261 | 283 | ||
| 262 | ;;; lread-tests.el ends here | 284 | ;;; lread-tests.el ends here |