Commit 97b9caf8 authored by Masaki Muranaka's avatar Masaki Muranaka

Check parameters strictly.

calloc in C99 is expected to return NULL when nelem * len == 0.
parent 4e877bc9
......@@ -184,16 +184,20 @@ mrb_malloc(mrb_state *mrb, size_t len)
void*
mrb_calloc(mrb_state *mrb, size_t nelem, size_t len)
{
void *p = NULL;
size_t size;
void *p;
if (nelem <= SIZE_MAX / len) {
if (nelem > 0 && len > 0 &&
nelem <= SIZE_MAX / len) {
size_t size;
size = nelem * len;
p = mrb_realloc(mrb, 0, size);
if (p && size > 0)
if (p) {
memset(p, 0, size);
}
} else {
p = NULL;
}
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