fix '(] infinite loop
authorAndy Wingo <wingo@pobox.com>
Tue, 13 Jul 2010 19:53:41 +0000 (21:53 +0200)
committerAndy Wingo <wingo@pobox.com>
Tue, 13 Jul 2010 19:53:41 +0000 (21:53 +0200)
* libguile/read.c (scm_read_sexp): Fix reader infinite loop. Thanks to
  Bill Schottstaedt for the report.
* test-suite/tests/reader.test: Add test.

libguile/read.c
test-suite/tests/reader.test

index d169167..df987c7 100644 (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));
 
index d1b9dda..b657861 100644 (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)
     ;; 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 "'(]")))
+
 
 \f
 (pass-if-exception "radix passed to number->string can't be zero"