From f1bec796bbda943fe1a0d01f9d1d5ea043b54cfc Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 22 Aug 2010 20:56:29 -0700 Subject: [PATCH] vm: C I/O streams became unusable after a single EOF (reported by John Benediktsson) --- vm/io.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vm/io.cpp b/vm/io.cpp index ba1e429802..2ea927bc05 100755 --- a/vm/io.cpp +++ b/vm/io.cpp @@ -190,7 +190,10 @@ void factor_vm::primitive_fgetc() int c = safe_fgetc(file); if(c == EOF && feof(file)) + { + clearerr(file); ctx->push(false_object); + } else ctx->push(tag_fixnum(c)); } @@ -210,11 +213,15 @@ void factor_vm::primitive_fread() size_t c = safe_fread(buf.untagged() + 1,1,size,file); if(c == 0) + { + clearerr(file); ctx->push(false_object); + } else { if(feof(file)) { + clearerr(file); byte_array *new_buf = allot_byte_array(c); memcpy(new_buf->data(), buf->data(),c); buf = new_buf;