Supplement to #6781

`mrb_str_dup()` always duplicates string objects in an unfrozen state, and the class is also set.
Therefore, it can be observed and modified from the Ruby side using the `ObjectSpace.each_object` method.

By using `mrb_str_dup_frozen()`, unnecessary duplication can be avoided, and modifications to the string can also be prevented.
This commit is contained in:
dearblue
2026-04-13 21:33:23 +09:00
parent d8e0d24fea
commit 9ad94a50e7
+1 -1
View File
@@ -386,7 +386,7 @@ mrb_str_format(mrb_state *mrb, mrb_int argc, const mrb_value *argv, mrb_value fm
buffer, so this is O(1); String#replace on the original goes
through str_replace which decrements the shared refcount, leaving
our copy's buffer intact. */
fmt = mrb_str_dup(mrb, fmt);
fmt = mrb_str_dup_frozen(mrb, fmt);
p = RSTRING_PTR(fmt);
end = p + RSTRING_LEN(fmt);
blen = 0;