diff --git a/pkgs/racket-test-core/tests/racket/file.rktl b/pkgs/racket-test-core/tests/racket/file.rktl index 771200589b..bf57219d63 100644 --- a/pkgs/racket-test-core/tests/racket/file.rktl +++ b/pkgs/racket-test-core/tests/racket/file.rktl @@ -1104,6 +1104,28 @@ (let ([x (+ 9 (expt 10 100))]) (test (list (cons x (add1 x))) regexp-match-peek-positions #"0" p (expt 10 100))))) +;; Make sure that peeking past the end of a +;; file as a first action gives EOF right away +(let ([tempfilename (make-temporary-file)]) + (call-with-output-file* + tempfilename + #:exists 'truncate + (lambda (o) (write-bytes (make-bytes 50 65) o))) + (for ([end '(60 50)]) + (test (list eof eof) + call-with-input-file + tempfilename + (lambda (i) + (list (peek-byte i end) + (peek-byte i end)))) + (test (list eof eof) + call-with-input-file + tempfilename + (lambda (i) + (list (peek-bytes 1 end i) + (peek-bytes 1 end i))))) + (delete-file tempfilename)) + ;;------------------------------------------------------------ ;; Test custom output port diff --git a/racket/src/racket/src/port.c b/racket/src/racket/src/port.c index a8c56a317e..062d8f16eb 100644 --- a/racket/src/racket/src/port.c +++ b/racket/src/racket/src/port.c @@ -1306,11 +1306,13 @@ intptr_t scheme_get_byte_string_unless(const char *who, } else if (v == SCHEME_SPECIAL) { ip->special = NULL; scheme_bad_time_for_special(who, port); - } else if (v == skip) { + } else if (v > 0) { peek_skip = scheme_bin_minus(peek_skip, scheme_make_integer(skip)); /* Ok... ready to continue (if skip == peek_skip) */ - } else + } else { + /* This shouldn't happen, but just in case */ return 0; + } } if (size) {