Permalink
Browse files

fix stack overflow in reader, #TRDR-11

Signed-off-by: Bronsa <brobronsa@gmail.com>
  • Loading branch information...
pmbauer authored and Bronsa committed Dec 5, 2013
1 parent ff37cfb commit 01b53cb61b586e78cf3f70f12ba2adbbdb7abb25
@@ -721,20 +721,21 @@
(when (= :unknown *read-eval*)
(reader-error "Reading disallowed - *read-eval* bound to :unknown"))
(try
- (log-source reader
- (let [ch (read-char reader)]
- (cond
- (whitespace? ch) (read reader eof-error? sentinel recursive?)
- (nil? ch) (if eof-error? (reader-error reader "EOF") sentinel)
- (number-literal? reader ch) (read-number reader ch)
- (comment-prefix? ch) (read (read-comment reader ch) eof-error? sentinel recursive?)
- :else (let [f (macros ch)]
- (if f
- (let [res (f reader ch)]
- (if (identical? res reader)
- (read reader eof-error? sentinel recursive?)
- res))
- (read-symbol reader ch))))))
+ (loop []
+ (log-source reader
+ (let [ch (read-char reader)]
+ (cond
+ (whitespace? ch) (recur)
+ (nil? ch) (if eof-error? (reader-error reader "EOF") sentinel)
+ (number-literal? reader ch) (read-number reader ch)
+ (comment-prefix? ch) (do (read-comment reader) (recur))
+ :else (let [f (macros ch)]
+ (if f
+ (let [res (f reader ch)]
+ (if (identical? res reader)
+ (recur)
+ res))
+ (read-symbol reader ch)))))))
(catch Exception e
(if (ex-info? e)
(throw e)
@@ -357,19 +357,20 @@
(read reader eof-error? eof opts)))
([reader eof-error? eof opts]
(try
- (let [ch (read-char reader)]
- (cond
- (whitespace? ch) (read opts reader)
- (nil? ch) (if eof-error? (reader-error reader "EOF") eof)
- (number-literal? reader ch) (read-number reader ch opts)
- (comment-prefix? ch) (read opts (read-comment reader ch opts))
- :else (let [f (macros ch)]
- (if f
- (let [res (f reader ch opts)]
- (if (identical? res reader)
- (read opts reader)
- res))
- (read-symbol reader ch)))))
+ (loop []
+ (let [ch (read-char reader)]
+ (cond
+ (whitespace? ch) (recur)
+ (nil? ch) (if eof-error? (reader-error reader "EOF") eof)
+ (number-literal? reader ch) (read-number reader ch opts)
+ (comment-prefix? ch) (do (read-comment reader) (recur))
+ :else (let [f (macros ch)]
+ (if f
+ (let [res (f reader ch opts)]
+ (if (identical? res reader)
+ (recur)
+ res))
+ (read-symbol reader ch))))))
(catch Exception e
(if (ex-info? e)
(throw e)
@@ -36,7 +36,7 @@
(defn skip-line
"Advances the reader to the end of a line. Returns the reader"
- [reader _]
+ [reader]
(loop []
(when-not (newline? (read-char reader))
(recur)))
@@ -119,7 +119,7 @@
(defn read-comment
[rdr & _]
- (skip-line rdr _))
+ (skip-line rdr))
(defn throwing-reader
[msg]

0 comments on commit 01b53cb

Please sign in to comment.