Commit a064038d authored by Masaki Muranaka's avatar Masaki Muranaka

Add a check for unsigned integer wrapping.

parent 47407768
......@@ -167,14 +167,16 @@ mrb_malloc(mrb_state *mrb, size_t len)
void*
mrb_calloc(mrb_state *mrb, size_t nelem, size_t len)
{
void *p;
void *p = NULL;
size_t size;
size = nelem * len;
p = mrb_realloc(mrb, 0, size);
if (nelem <= SIZE_MAX / len) {
size = nelem * len;
p = mrb_realloc(mrb, 0, size);
if (p && size > 0)
memset(p, 0, size);
if (p && size > 0)
memset(p, 0, size);
}
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