Skip to content
Snippets Groups Projects
Commit c3a9a6c1 authored by Henry's avatar Henry
Browse files

int??IO: handle overflow errors

parent 3673b65b
Branches
Tags
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2014-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -29,6 +29,7 @@ License ...@@ -29,6 +29,7 @@ License
#include "IOstreams.H" #include "IOstreams.H"
#include <sstream> #include <sstream>
#include <cerrno>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -85,9 +86,10 @@ int32_t Foam::readInt32(Istream& is) ...@@ -85,9 +86,10 @@ int32_t Foam::readInt32(Istream& is)
bool Foam::read(const char* buf, int32_t& s) bool Foam::read(const char* buf, int32_t& s)
{ {
char *endptr = NULL; char *endptr = NULL;
errno = 0;
long l = strtol(buf, &endptr, 10); long l = strtol(buf, &endptr, 10);
s = int32_t(l); s = int32_t(l);
return (*endptr == 0); return (*endptr == 0) && (errno == 0);
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2014-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -29,6 +29,7 @@ License ...@@ -29,6 +29,7 @@ License
#include "IOstreams.H" #include "IOstreams.H"
#include <sstream> #include <sstream>
#include <cerrno>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -85,9 +86,10 @@ int64_t Foam::readInt64(Istream& is) ...@@ -85,9 +86,10 @@ int64_t Foam::readInt64(Istream& is)
bool Foam::read(const char* buf, int64_t& s) bool Foam::read(const char* buf, int64_t& s)
{ {
char *endptr = NULL; char *endptr = NULL;
errno = 0;
long l = strtol(buf, &endptr, 10); long l = strtol(buf, &endptr, 10);
s = int64_t(l); s = int64_t(l);
return (*endptr == 0); return (*endptr == 0) && (errno == 0);
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment