mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
string.c: mrb_str_to_cstr() should always return a mutable string.
This commit is contained in:
+8
-1
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user