Merge pull request #92 from palkan/master

Handle shared/frozen strings in IO#sysread
This commit is contained in:
Tomoyuki Sahara
2017-10-05 21:27:58 +09:00
committed by GitHub
2 changed files with 8 additions and 0 deletions
+3
View File
@@ -630,8 +630,11 @@ mrb_io_sysread(mrb_state *mrb, mrb_value io)
if (mrb_nil_p(buf)) {
buf = mrb_str_new(mrb, NULL, maxlen);
}
if (RSTRING_LEN(buf) != maxlen) {
buf = mrb_str_resize(mrb, buf, maxlen);
} else {
mrb_str_modify(mrb, RSTRING(buf));
}
fptr = (struct mrb_io *)io_get_open_fptr(mrb, io);
+5
View File
@@ -250,6 +250,11 @@ assert('IO.sysopen, IO#sysread') do
io.sysread(10000)
io.sysread(10000)
end
assert_raise RuntimeError do
io.sysread(5, "abcde".freeze)
end
io.close
assert_equal "", io.sysread(0)
assert_raise(IOError) { io.sysread(1) }