Merge pull request #351 from monaka/pr-brush-up-mrb_calloc

Brush up mrb_calloc().
This commit is contained in:
Yukihiro "Matz" Matsumoto
2012-07-07 08:27:07 -07:00
+10 -3
View File
@@ -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;
}