runtime/rfc2822-headers: Watch out for eof-object.
authorMatt Birkholz <matt@birchwood-abbey.net>
Sat, 8 Dec 2018 20:07:32 +0000 (13:07 -0700)
committerMatt Birkholz <matt@birchwood-abbey.net>
Sat, 8 Dec 2018 20:07:32 +0000 (13:07 -0700)
And leave parse-error calls in tail position, so as not to frustrate a
debugger expecting to return the correct answer.

src/runtime/rfc2822-headers.scm

index cf48079370f50eeb9faca3cfc4265458e6a2648c..fd7aae296258d58ecd4a00f3a9126ab754b67504 100644 (file)
@@ -191,26 +191,32 @@ USA.
                       byte
                       (builder)))
                  ((fix:= 13 byte)
-                  (if (fix:= 10 (peek-u8 port))
-                      (read-u8 port)
-                      (parse-error port "Invalid line ending:"
-                                   'read-ascii-line))
+                  (let ((byte (peek-u8 port)))
+                    (cond ((eof-object? byte)
+                           (parse-error port "Truncated line ending:"
+                                        'read-ascii-line))
+                          ((fix:= 10 byte)
+                           (read-u8 port))
+                          (else
+                           (parse-error port "Invalid line ending:"
+                                        'read-ascii-line))))
                   (builder))
                  ((fix:= 10 byte)
-                  (parse-error port "Invalid line ending:" 'read-ascii-line)
-                  (builder))
+                  (parse-error port "Invalid line ending:" 'read-ascii-line))
                  ((and (fix:<= 32 byte) (fix:<= byte 126))
                   (builder (integer->char byte))
                   (loop))
                  (else
                   (parse-error port "Illegal character:" 'read-ascii-line)
-                  (loop)))))))))
+                  ))))))))
 
 (define (peek-ascii-char port)
   (let ((byte (peek-u8 port)))
-    (if (eof-object? byte)
-       byte
-       (integer->char byte))))
+    (cond ((eof-object? byte)
+          byte)
+         ((and (fix:<= 32 byte) (fix:<= byte 126))
+          (integer->char byte))
+         (else (parse-error port "Illegal character:" 'peek-ascii-char)))))
 
 (define (skip-wsp-left string start end)
   (let loop ((i start))