Commit 7eb86a4a authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

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

Brush up mrb_calloc().
parents 3b8ad4c3 a064038d
...@@ -167,10 +167,17 @@ mrb_malloc(mrb_state *mrb, size_t len) ...@@ -167,10 +167,17 @@ mrb_malloc(mrb_state *mrb, size_t len)
void* void*
mrb_calloc(mrb_state *mrb, size_t nelem, size_t len) 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; 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