Fix improper termlen fill in str_duplicate_setup_embed.

When term len != 1 (for example: Encoding::UTF32BE), term fill is wrong size.
This commit is contained in:
Luke Gruber 2025-11-12 12:51:47 -05:00 committed by Nobuyoshi Nakada
parent 9de66a8c51
commit 371a295e19
Notes: git 2025-11-17 15:54:14 +00:00

View File

@ -1935,8 +1935,8 @@ str_duplicate_setup_embed(VALUE klass, VALUE str, VALUE dup)
long len = RSTRING_LEN(str);
RUBY_ASSERT(STR_EMBED_P(dup));
RUBY_ASSERT(str_embed_capa(dup) >= len + 1);
MEMCPY(RSTRING(dup)->as.embed.ary, RSTRING(str)->as.embed.ary, char, len + 1);
RUBY_ASSERT(str_embed_capa(dup) >= len + TERM_LEN(str));
MEMCPY(RSTRING(dup)->as.embed.ary, RSTRING(str)->as.embed.ary, char, len + TERM_LEN(str));
STR_SET_LEN(dup, RSTRING_LEN(str));
return str_duplicate_setup_encoding(str, dup, flags);
}