diff options
author | nagachika <nagachika@ruby-lang.org> | 2022-11-13 11:13:53 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2022-11-13 11:13:53 +0900 |
commit | db1aa39ffcaa5b9f062639eb30c76959f4607a8e (patch) | |
tree | 622402ec48796817a8f609e8dd2855770b8bf9b0 /pack.c | |
parent | 0f334f90d00821d32be0ba1835baa9efc61b782b (diff) |
merge revision(s) 199b59f065ce6f1c13b8424f35a70c513523211b: [Backport #19116]
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]
---
pack.c | 1 +
test/ruby/test_array.rb | 6 ++++++
2 files changed, 7 insertions(+)
Diffstat (limited to 'pack.c')
-rw-r--r-- | pack.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -212,12 +212,13 @@ pack_pack(rb_execution_context_t *ec, VALUE ary, VALUE fmt, VALUE buffer) pend = p + RSTRING_LEN(fmt); if (NIL_P(buffer)) { - res = rb_str_buf_new(0); + res = rb_str_buf_new(0); } else { if (!RB_TYPE_P(buffer, T_STRING)) rb_raise(rb_eTypeError, "buffer must be String, not %s", rb_obj_classname(buffer)); - res = buffer; + rb_str_modify(buffer); + res = buffer; } idx = 0; |