IO#read always check the provided buffer is mutable
Otherwise you can have work in some circumstance but not in others.
This commit is contained in:
parent
0f02fbd9ff
commit
b013aae0c6
3
io.c
3
io.c
@ -3276,9 +3276,10 @@ io_setstrbuf(VALUE *str, long len)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE s = StringValue(*str);
|
VALUE s = StringValue(*str);
|
||||||
|
rb_str_modify(s);
|
||||||
|
|
||||||
long clen = RSTRING_LEN(s);
|
long clen = RSTRING_LEN(s);
|
||||||
if (clen >= len) {
|
if (clen >= len) {
|
||||||
rb_str_modify(s);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
len -= clen;
|
len -= clen;
|
||||||
|
@ -299,6 +299,32 @@ describe "IO#read" do
|
|||||||
@io.read(10, buf).should == nil
|
@io.read(10, buf).should == nil
|
||||||
|
|
||||||
buf.should == ''
|
buf.should == ''
|
||||||
|
|
||||||
|
buf = 'non-empty string'
|
||||||
|
|
||||||
|
@io.read(nil, buf).should == ""
|
||||||
|
|
||||||
|
buf.should == ''
|
||||||
|
|
||||||
|
buf = 'non-empty string'
|
||||||
|
|
||||||
|
@io.read(0, buf).should == ""
|
||||||
|
|
||||||
|
buf.should == ''
|
||||||
|
end
|
||||||
|
|
||||||
|
it "raise FrozenError if the output buffer is frozen" do
|
||||||
|
@io.read
|
||||||
|
-> { @io.read(0, 'frozen-string'.freeze) }.should raise_error(FrozenError)
|
||||||
|
-> { @io.read(1, 'frozen-string'.freeze) }.should raise_error(FrozenError)
|
||||||
|
-> { @io.read(nil, 'frozen-string'.freeze) }.should raise_error(FrozenError)
|
||||||
|
end
|
||||||
|
|
||||||
|
ruby_bug "", ""..."3.3" do
|
||||||
|
it "raise FrozenError if the output buffer is frozen (2)" do
|
||||||
|
@io.read
|
||||||
|
-> { @io.read(1, ''.freeze) }.should raise_error(FrozenError)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "consumes zero bytes when reading zero bytes" do
|
it "consumes zero bytes when reading zero bytes" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user