Fix bug in array pack with shared strings

If string literals are long and they become shared, we need to make them
independent before we can write to them. [Bug #19116]
This commit is contained in:
Jemma Issroff 2022-11-09 17:04:35 -05:00 коммит произвёл Peter Zhu
Родитель 68bd1d6855
Коммит 199b59f065
2 изменённых файлов: 7 добавлений и 0 удалений

1
pack.c
Просмотреть файл

@ -217,6 +217,7 @@ pack_pack(rb_execution_context_t *ec, VALUE ary, VALUE fmt, VALUE buffer)
else {
if (!RB_TYPE_P(buffer, T_STRING))
rb_raise(rb_eTypeError, "buffer must be String, not %s", rb_obj_classname(buffer));
rb_str_modify(buffer);
res = buffer;
}

Просмотреть файл

@ -1294,6 +1294,12 @@ class TestArray < Test::Unit::TestCase
=end
end
def test_pack_with_buffer
n = [ 65, 66, 67 ]
str = "a" * 100
assert_equal("aaaABC", n.pack("@3ccc", buffer: str.dup), "[Bug #19116]")
end
def test_pop
a = @cls[ 'cat', 'dog' ]
assert_equal('dog', a.pop)