Fix calloc not erroring on multiplication overflow.

This commit is contained in:
Jonas 'Sortie' Termansen 2014-04-22 17:49:49 +02:00
parent 4674017303
commit 01b8acbc90
1 changed files with 5 additions and 1 deletions

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014.
This file is part of the Sortix C Library.
@ -22,11 +22,15 @@
*******************************************************************************/
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
extern "C" void* calloc(size_t nmemb, size_t size)
{
if ( size && nmemb && SIZE_MAX / size < nmemb )
return errno = ENOMEM, (void*) NULL;
size_t total = nmemb * size;
void* result = malloc(total);
if ( !result )