mrb_str_new(mrb, "", len) creates an unmodifiable string object; ref #2674

parent 0c4d053a
...@@ -356,7 +356,7 @@ mrb_str_prepend(mrb_state *mrb, mrb_value self) ...@@ -356,7 +356,7 @@ mrb_str_prepend(mrb_state *mrb, mrb_value self)
} }
s2 = mrb_str_ptr(other); s2 = mrb_str_ptr(other);
len = RSTR_LEN(s1) + RSTR_LEN(s2); len = RSTR_LEN(s1) + RSTR_LEN(s2);
temp_str = mrb_str_new(mrb, "", RSTR_LEN(s1)); temp_str = mrb_str_new(mrb, NULL, RSTR_LEN(s1));
temp_s = mrb_str_ptr(temp_str); temp_s = mrb_str_ptr(temp_str);
memcpy(RSTR_PTR(temp_s), RSTR_PTR(s1), RSTR_LEN(s1)); memcpy(RSTR_PTR(temp_s), RSTR_PTR(s1), RSTR_LEN(s1));
if (RSTRING_CAPA(self) < len) { if (RSTRING_CAPA(self) < len) {
......
...@@ -163,7 +163,7 @@ str_new(mrb_state *mrb, const char *p, size_t len) ...@@ -163,7 +163,7 @@ str_new(mrb_state *mrb, const char *p, size_t len)
{ {
struct RString *s; struct RString *s;
if (mrb_ro_data_p(p)) { if (p && mrb_ro_data_p(p)) {
return str_new_static(mrb, p, len); return str_new_static(mrb, p, len);
} }
s = mrb_obj_alloc_string(mrb); s = mrb_obj_alloc_string(mrb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment