summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/string.c b/src/string.c
index 7983a925e..2b47b06ca 100644
--- a/src/string.c
+++ b/src/string.c
@@ -2182,6 +2182,10 @@ mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr)
char *p = RSTR_PTR(ps);
if (!p || p[len] != '\0') {
+ if (RSTR_FROZEN_P(ps)) {
+ *ptr = str = mrb_str_dup(mrb, str);
+ ps = mrb_str_ptr(str);
+ }
mrb_str_modify(mrb, ps);
return RSTR_PTR(ps);
}