intIO: handle overflow errors
Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=1532
This commit is contained in:
parent
b3e08bb2b8
commit
57407a029c
1 changed files with 3 additions and 1 deletions
|
|
@ -35,6 +35,7 @@ Description
|
|||
#include "IOstreams.H"
|
||||
|
||||
#include <sstream>
|
||||
#include <cerrno>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
|
@ -91,9 +92,10 @@ int Foam::readInt(Istream& is)
|
|||
bool Foam::readInt(const char* buf, int& s)
|
||||
{
|
||||
char *endptr = NULL;
|
||||
errno = 0;
|
||||
long l = strtol(buf, &endptr, 10);
|
||||
s = int(l);
|
||||
return (*endptr == 0);
|
||||
return (*endptr == 0) && (errno == 0) && (l >= INT_MIN) && (l <= INT_MAX);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue