mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Fix atoi(3) out-of-range cases.
This commit is contained in:
parent
87fee95949
commit
94a7433cf0
1 changed files with 9 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2011.
|
Copyright(C) Jonas 'Sortie' Termansen 2011, 2014.
|
||||||
|
|
||||||
This file is part of the Sortix C Library.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -22,9 +22,16 @@
|
||||||
|
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
extern "C" int atoi(const char* str)
|
extern "C" int atoi(const char* str)
|
||||||
{
|
{
|
||||||
return (int) strtol(str, (char**) NULL, 10);
|
long long_result = strtol(str, (char**) NULL, 10);
|
||||||
|
if ( long_result < INT_MIN )
|
||||||
|
return errno = ERANGE, INT_MIN;
|
||||||
|
if ( INT_MAX < long_result )
|
||||||
|
return errno = ERANGE, INT_MAX;
|
||||||
|
return (int) long_result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue