Validate string type when constructing IO::Buffer for string mapping.

This commit is contained in:
Samuel Williams 2021-11-15 15:28:02 +13:00
parent a19a657514
commit 5190926e40
Notes: git 2021-11-17 06:40:14 +09:00
2 changed files with 10 additions and 0 deletions

View File

@ -259,6 +259,8 @@ rb_io_buffer_type_allocate(VALUE self)
VALUE
rb_io_buffer_type_for(VALUE klass, VALUE string)
{
StringValue(string);
VALUE instance = rb_io_buffer_type_allocate(klass);
struct rb_io_buffer *data = NULL;

View File

@ -81,6 +81,14 @@ class TestIOBuffer < Test::Unit::TestCase
assert_equal "Hello World", string
end
def test_non_string
not_string = Object.new
assert_raise TypeError do
IO::Buffer.for(not_string)
end
end
def test_resize
buffer = IO::Buffer.new(1024, IO::Buffer::MAPPED)
buffer.resize(2048, 0)