summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2022-11-13 11:13:53 +0900
committernagachika <nagachika@ruby-lang.org>2022-11-13 11:13:53 +0900
commitdb1aa39ffcaa5b9f062639eb30c76959f4607a8e (patch)
tree622402ec48796817a8f609e8dd2855770b8bf9b0
parent0f334f90d00821d32be0ba1835baa9efc61b782b (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(+)
-rw-r--r--pack.c5
-rw-r--r--test/ruby/test_array.rb6
-rw-r--r--version.h4
3 files changed, 11 insertions, 4 deletions
diff --git a/pack.c b/pack.c
index 1fbbd724d7..7de07a51d1 100644
--- a/pack.c
+++ b/pack.c
@@ -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;
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index a97a9c2558..ccbe85877f 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -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)
diff --git a/version.h b/version.h
index 043cd33b38..8a59f3ea0d 100644
--- a/version.h
+++ b/version.h
@@ -11,11 +11,11 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 3
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 177
+#define RUBY_PATCHLEVEL 178
#define RUBY_RELEASE_YEAR 2022
#define RUBY_RELEASE_MONTH 11
-#define RUBY_RELEASE_DAY 5
+#define RUBY_RELEASE_DAY 13
#include "ruby/version.h"