mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Fix underlying bugs. mrb_calloc will be crashed in case "nelem == 0" or "p == NULL"
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user