Fix calloc not erroring on multiplication overflow.
This commit is contained in:
parent
4674017303
commit
01b8acbc90
|
@ -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.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -22,11 +22,15 @@
|
||||||
|
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
extern "C" void* calloc(size_t nmemb, size_t size)
|
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;
|
size_t total = nmemb * size;
|
||||||
void* result = malloc(total);
|
void* result = malloc(total);
|
||||||
if ( !result )
|
if ( !result )
|
||||||
|
|
Loading…
Reference in New Issue