Commit f8121953 authored by Tomoyuki Sahara's avatar Tomoyuki Sahara Committed by GitHub

Merge pull request #92 from palkan/master

Handle shared/frozen strings in IO#sysread
parents 04774e5b 43795cb1
...@@ -630,8 +630,11 @@ mrb_io_sysread(mrb_state *mrb, mrb_value io) ...@@ -630,8 +630,11 @@ mrb_io_sysread(mrb_state *mrb, mrb_value io)
if (mrb_nil_p(buf)) { if (mrb_nil_p(buf)) {
buf = mrb_str_new(mrb, NULL, maxlen); buf = mrb_str_new(mrb, NULL, maxlen);
} }
if (RSTRING_LEN(buf) != maxlen) { if (RSTRING_LEN(buf) != maxlen) {
buf = mrb_str_resize(mrb, 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); fptr = (struct mrb_io *)io_get_open_fptr(mrb, io);
......
...@@ -250,6 +250,11 @@ assert('IO.sysopen, IO#sysread') do ...@@ -250,6 +250,11 @@ assert('IO.sysopen, IO#sysread') do
io.sysread(10000) io.sysread(10000)
io.sysread(10000) io.sysread(10000)
end end
assert_raise RuntimeError do
io.sysread(5, "abcde".freeze)
end
io.close io.close
assert_equal "", io.sysread(0) assert_equal "", io.sysread(0)
assert_raise(IOError) { io.sysread(1) } assert_raise(IOError) { io.sysread(1) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment