Merge pull request #6656 from dearblue/combination_init.2

This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-10-29 11:01:29 +09:00
committed by GitHub
2 changed files with 11 additions and 7 deletions
+5 -3
View File
@@ -243,15 +243,17 @@ mrb_calloc(mrb_state *mrb, size_t nelem, size_t len)
{
void *p;
if (nelem > 0 && len > 0 &&
nelem <= SIZE_MAX / len) {
if (nelem == 0 || len == 0) {
p = NULL;
}
else if (nelem <= SIZE_MAX / len) {
size_t size = nelem * len;
p = mrb_malloc(mrb, size);
memset(p, 0, size);
}
else {
p = NULL;
mrb_raise(mrb, E_ARGUMENT_ERROR, "memory allocation overflow");
}
return p;