From 9ad94a50e7ac7027ceb43ec0cdbe5fa980b038bd Mon Sep 17 00:00:00 2001 From: dearblue Date: Mon, 13 Apr 2026 21:33:23 +0900 Subject: [PATCH] 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. --- mrbgems/mruby-sprintf/src/sprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrbgems/mruby-sprintf/src/sprintf.c b/mrbgems/mruby-sprintf/src/sprintf.c index c7fbf4397..6cbef79a4 100644 --- a/mrbgems/mruby-sprintf/src/sprintf.c +++ b/mrbgems/mruby-sprintf/src/sprintf.c @@ -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;