Commit 47407768 authored by Masaki Muranaka's avatar Masaki Muranaka

Fix underlying bugs. mrb_calloc will be crashed in case "nelem == 0" or "p == NULL"

parent 8268ba27
......@@ -167,10 +167,15 @@ mrb_malloc(mrb_state *mrb, size_t len)
void*
mrb_calloc(mrb_state *mrb, size_t nelem, size_t len)
{
void *p = mrb_realloc(mrb, 0, nelem*len);
void *p;
size_t size;
size = nelem * len;
p = mrb_realloc(mrb, 0, size);
if (p && size > 0)
memset(p, 0, size);
if (len > 0)
memset(p, 0, nelem*len);
return p;
}
......
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