int??IO: handle overflow errors

This commit is contained in:
Henry
2015-02-16 22:16:21 +00:00
parent 3673b65b61
commit c3a9a6c10f
2 changed files with 8 additions and 4 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2014 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2014-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -29,6 +29,7 @@ License
#include "IOstreams.H"
#include <sstream>
#include <cerrno>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -85,9 +86,10 @@ int32_t Foam::readInt32(Istream& is)
bool Foam::read(const char* buf, int32_t& s)
{
char *endptr = NULL;
errno = 0;
long l = strtol(buf, &endptr, 10);
s = int32_t(l);
return (*endptr == 0);
return (*endptr == 0) && (errno == 0);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2014 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2014-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -29,6 +29,7 @@ License
#include "IOstreams.H"
#include <sstream>
#include <cerrno>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -85,9 +86,10 @@ int64_t Foam::readInt64(Istream& is)
bool Foam::read(const char* buf, int64_t& s)
{
char *endptr = NULL;
errno = 0;
long l = strtol(buf, &endptr, 10);
s = int64_t(l);
return (*endptr == 0);
return (*endptr == 0) && (errno == 0);
}