summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2022-01-06 13:35:17 -0500
committerPeter Zhu <peter@peterzhu.ca>2022-01-06 14:33:35 -0500
commit5f55b03716f0fc8aab227c8a752eefed2a58b38f (patch)
tree81c5cd250fa770e8b42d292aac0b295ce2e4cc0b /string.c
parent44368b5f8bc21e19fa06a0fc0625923fc41293e6 (diff)
Set correct termlen for frozen strings
Frozen strings should have the same termlen as the original string when copy_encoding is true.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5399
Diffstat (limited to 'string.c')
-rw-r--r--string.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/string.c b/string.c
index 5b3c7cd57b..389af1e73a 100644
--- a/string.c
+++ b/string.c
@@ -1419,9 +1419,10 @@ str_new_frozen_buffer(VALUE klass, VALUE orig, int copy_encoding)
VALUE str;
long len = RSTRING_LEN(orig);
+ int termlen = copy_encoding ? TERM_LEN(orig) : 1;
- if (STR_EMBED_P(orig) || STR_EMBEDDABLE_P(len, 1)) {
- str = str_new(klass, RSTRING_PTR(orig), len);
+ if (STR_EMBED_P(orig) || STR_EMBEDDABLE_P(len, termlen)) {
+ str = str_new0(klass, RSTRING_PTR(orig), len, termlen);
assert(STR_EMBED_P(str));
}
else {