mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #351 from monaka/pr-brush-up-mrb_calloc
Brush up mrb_calloc().
This commit is contained in:
@@ -167,10 +167,17 @@ 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 = NULL;
|
||||
size_t size;
|
||||
|
||||
if (nelem <= SIZE_MAX / len) {
|
||||
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