From c417d1f39d3bd98b73aab9ae8fb8c68e545cc56f Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 31 Jan 2011 06:47:37 -0700 Subject: [PATCH] fix `read-language' exn construction in an EOF case Closes PR 11683 Merge to 5.1 (cherry picked from commit dd5f0dfc80ddaf6e7d3215519a08d907928c0e5a) --- collects/tests/racket/read.rktl | 7 +++++++ src/racket/src/read.c | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/collects/tests/racket/read.rktl b/collects/tests/racket/read.rktl index 38f93b84d3..3ccbb96391 100644 --- a/collects/tests/racket/read.rktl +++ b/collects/tests/racket/read.rktl @@ -1103,6 +1103,13 @@ ;; Check error-message formatting: (err/rt-test (read (open-input-string "#l")) (lambda (exn) (regexp-match? #rx"`#l'" (exn-message exn)))) +;; Make sure read-language error here is this can comes from read-language +;; and not from an ill-formed srcloc construction: +(let () + (define p (open-input-string ";\n")) + (port-count-lines! p) + (err/rt-test (read-language p) + (lambda (exn) (regexp-match? #rx"read-language" (exn-message exn))))) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/src/racket/src/read.c b/src/racket/src/read.c index 6f0535b408..fb99bc50eb 100644 --- a/src/racket/src/read.c +++ b/src/racket/src/read.c @@ -992,6 +992,13 @@ read_inner_inner(Scheme_Object *port, Scheme_Object *stxsrc, Scheme_Hash_Table * dispatch_ch = ch; if (get_info && (dispatch_ch != '#') && (dispatch_ch != ';')) { + /* If ch is EOF, then col or pos wasn't incremented by reading ch. + The col and pos might be used in an error message, which expects + to subtract one from each --- so counteract by adding one here. */ + if (ch == EOF) { + if (pos >= 0) pos++; + if (col >= 0) col++; + } return expected_lang("", ch, port, stxsrc, line, col, pos, get_info); }