intIO: handle overflow errors

Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=1532
This commit is contained in:
Henry 2015-02-16 22:01:53 +00:00
parent b3e08bb2b8
commit 57407a029c

View file

@ -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);
}