mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Should allocate memory region before updating len; fix #3842
Otherwise half-baked string object will be allocated.
This commit is contained in:
+1
-1
@@ -70,9 +70,9 @@ str_new(mrb_state *mrb, const char *p, size_t len)
|
||||
if (len >= MRB_INT_MAX) {
|
||||
mrb_raise(mrb, E_ARGUMENT_ERROR, "string size too big");
|
||||
}
|
||||
s->as.heap.ptr = (char *)mrb_malloc(mrb, len+1);
|
||||
s->as.heap.len = (mrb_int)len;
|
||||
s->as.heap.aux.capa = (mrb_int)len;
|
||||
s->as.heap.ptr = (char *)mrb_malloc(mrb, len+1);
|
||||
if (p) {
|
||||
memcpy(s->as.heap.ptr, p, len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user