mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Fix calloc not erroring on multiplication overflow.
This commit is contained in:
parent
4674017303
commit
01b8acbc90
1 changed files with 5 additions and 1 deletions
|
@ -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 )
|
||||
|
|
Loading…
Add table
Reference in a new issue