Signal an error instead of giving the caller less memory than they asked

for when num * size would cause integer overflow.

MFC after:	1 week
This commit is contained in:
tjr 2002-08-04 02:52:11 +00:00
parent c3ab10b179
commit 79a3f64da0

View File

@ -37,6 +37,8 @@ static char sccsid[] = "@(#)calloc.c 8.1 (Berkeley) 6/4/93";
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
@ -47,6 +49,11 @@ calloc(num, size)
{
void *p;
if (size != 0 && SIZE_MAX / size < num) {
errno = ENOMEM;
return (NULL);
}
size *= num;
if ( (p = malloc(size)) )
bzero(p, size);