diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-11-08 08:46:08 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-11-08 08:46:55 +0900 |
| commit | f723832ebc6b3fef41ca4e81a172cb2d8f27b7de (patch) | |
| tree | ecd288a05bcda8b4bd893654b103c66ba5740284 /src/string.c | |
| parent | 7ae20e0785704bce1a5bf7183fc9202336ad8676 (diff) | |
| download | mruby-f723832ebc6b3fef41ca4e81a172cb2d8f27b7de.tar.gz mruby-f723832ebc6b3fef41ca4e81a172cb2d8f27b7de.zip | |
Should allocate memory region before updating `len`; fix #3842
Otherwise half-baked string object will be allocated.
Diffstat (limited to 'src/string.c')
| -rw-r--r-- | src/string.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/string.c b/src/string.c index 8f0db681c..da475839c 100644 --- a/src/string.c +++ b/src/string.c @@ -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); } |
