1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

fix '(] infinite loop

* libguile/read.c (scm_read_sexp): Fix reader infinite loop. Thanks to
  Bill Schottstaedt for the report.
* test-suite/tests/reader.test: Add test.
This commit is contained in:
Andy Wingo 2010-07-13 21:53:41 +02:00
parent aa77dace40
commit 5b69315ed3
2 changed files with 21 additions and 3 deletions

View file

@ -392,9 +392,15 @@ scm_read_sexp (scm_t_wchar chr, SCM port)
{
SCM new_tail;
if (c == ')' || (SCM_SQUARE_BRACKETS_P && c == ']'))
scm_i_input_error (FUNC_NAME, port,
"in pair: mismatched close paren: ~A",
scm_list_1 (SCM_MAKE_CHAR (c)));
scm_ungetc (c, port);
if (scm_is_eq (scm_sym_dot,
(tmp = scm_read_expression (port))))
tmp = scm_read_expression (port);
if (scm_is_eq (scm_sym_dot, tmp))
{
SCM_SETCDR (tl, tmp = scm_read_expression (port));

View file

@ -38,6 +38,8 @@
(cons 'read-error "illegal character in escape sequence: .*$"))
(define exception:missing-expression
(cons 'read-error "no expression after #;"))
(define exception:mismatched-paren
(cons 'read-error "mismatched close paren"))
(define (read-string s)
@ -131,7 +133,17 @@
;; mutable objects.
(let ((str (with-input-from-string "\"hello, world\"" read)))
(string-set! str 0 #\H)
(string=? str "Hello, world"))))
(string=? str "Hello, world")))
(pass-if "square brackets are parens"
(equal? '() (read-string "[]")))
(pass-if-exception "paren mismatch" exception:unexpected-rparen
(read-string "'[)"))
(pass-if-exception "paren mismatch (2)" exception:mismatched-paren
(read-string "'(]")))
(pass-if-exception "radix passed to number->string can't be zero"