summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/io.c b/io.c
index c1c7d511db..1dba2ea69a 100644
--- a/io.c
+++ b/io.c
@@ -482,11 +482,15 @@ io_read(argc, argv, io)
}
len = NUM2INT(length);
+ if (len < 0) {
+ rb_raise(rb_eArgError, "negative length %d given", len);
+ }
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
if (feof(fptr->f)) return Qnil;
str = rb_str_new(0, len);
+ if (len == 0) return str;
READ_CHECK(fptr->f);
n = io_fread(RSTRING(str)->ptr, len, fptr->f);