mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user