From 8b02ad57a60a13ed8327d2e16231fcfe853b51d6 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 23 Nov 2004 16:04:16 +0000 Subject: * io.c (io_read): [ruby-dev:24952] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@7359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index f8237175d..7145e834d 100644 --- a/io.c +++ b/io.c @@ -1197,17 +1197,19 @@ io_read(argc, argv, io) rb_scan_args(argc, argv, "02", &length, &str); + if (!NIL_P(length)) { + len = NUM2LONG(length); + if (len < 0) { + rb_raise(rb_eArgError, "negative length %ld given", len); + } + } + GetOpenFile(io, fptr); rb_io_check_readable(fptr); + if (NIL_P(length)) { return read_all(fptr, remain_size(fptr), str); } - - len = NUM2LONG(length); - if (len < 0) { - rb_raise(rb_eArgError, "negative length %ld given", len); - } - if (feof(fptr->f)) return Qnil; if (NIL_P(str)) { str = rb_str_new(0, len); -- cgit