summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-08-18 21:40:10 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-08-18 21:40:10 +0900
commitef66406c507639871797e53e7bf82898c21ca022 (patch)
tree18ed98ab4b1004f0822a8d61dcc67b6bcf3a8cd6 /src/string.c
parent20635e6bdc2899d649c2f3fe12f4e82739ee2a54 (diff)
downloadmruby-ef66406c507639871797e53e7bf82898c21ca022.tar.gz
mruby-ef66406c507639871797e53e7bf82898c21ca022.zip
string.c: `mrb_str_to_cstr()` should always return a mutable string.
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/string.c b/src/string.c
index 7d7915323..97e115a19 100644
--- a/src/string.c
+++ b/src/string.c
@@ -835,8 +835,15 @@ mrb_str_to_cstr(mrb_state *mrb, mrb_value str0)
{
struct RString *s;
+ const char *p = RSTRING_PTR(str0);
+ size_t len = RSTRING_LEN(str0);
check_null_byte(mrb, str0);
- s = str_new(mrb, RSTRING_PTR(str0), RSTRING_LEN(str0));
+ if (RSTR_EMBEDDABLE_P(len)) {
+ s = str_init_embed(mrb_obj_alloc_string(mrb), p, len);
+ }
+ else {
+ s = str_init_normal(mrb, mrb_obj_alloc_string(mrb), p, len);
+ }
return RSTR_PTR(s);
}