bounds check for parse-stream-debug-info on empty input (fixes issue #826)

This commit is contained in:
Alex Shinn 2022-04-18 08:55:06 +09:00
parent 899a6bace3
commit d4eb32f8b1
2 changed files with 14 additions and 10 deletions

View file

@ -21,6 +21,7 @@
(test-not (parse parse-nothing "")) (test-not (parse parse-nothing ""))
(test-not (parse parse-nothing "a")) (test-not (parse parse-nothing "a"))
(test-error (parse-fully parse-nothing ""))
(test-not (parse (parse-char #\a) "")) (test-not (parse (parse-char #\a) ""))
(test-assert (parse-fully (parse-char #\a) "a")) (test-assert (parse-fully (parse-char #\a) "a"))

View file

@ -167,16 +167,19 @@
;; location ;; location
(if (%parse-stream-tail s) (if (%parse-stream-tail s)
(parse-stream-debug-info (%parse-stream-tail s) i) (parse-stream-debug-info (%parse-stream-tail s) i)
(let* ((line-info (let ((max-char (parse-stream-max-char s)))
(parse-stream-count-lines s (parse-stream-max-char s))) (if (< max-char 0)
(line (+ (parse-stream-line s) (car line-info))) (list 0 0 "")
(col (if (zero? (car line-info)) (let* ((line-info
(+ (parse-stream-column s) (cadr line-info)) (parse-stream-count-lines s max-char))
(cadr line-info))) (line (+ (parse-stream-line s) (car line-info)))
(from (car (cddr line-info))) (col (if (zero? (car line-info))
(to (parse-stream-end-of-line s (+ from 1))) (+ (parse-stream-column s) (cadr line-info))
(str (parse-stream-substring s from s to))) (cadr line-info)))
(list line col str)))) (from (car (cddr line-info)))
(to (parse-stream-end-of-line s (+ from 1)))
(str (parse-stream-substring s from s to)))
(list line col str))))))
(define (parse-stream-next-source source i) (define (parse-stream-next-source source i)
(if (>= (+ i 1) (vector-length (parse-stream-buffer source))) (if (>= (+ i 1) (vector-length (parse-stream-buffer source)))