From c3a9a6c10f28c438588d1ea34cc3c27b61f68417 Mon Sep 17 00:00:00 2001 From: Henry <Henry> Date: Mon, 16 Feb 2015 22:16:21 +0000 Subject: [PATCH] int??IO: handle overflow errors --- src/OpenFOAM/primitives/ints/int32/int32IO.C | 6 ++++-- src/OpenFOAM/primitives/ints/int64/int64IO.C | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/OpenFOAM/primitives/ints/int32/int32IO.C b/src/OpenFOAM/primitives/ints/int32/int32IO.C index 209e9ae0d12..0b18d97028f 100644 --- a/src/OpenFOAM/primitives/ints/int32/int32IO.C +++ b/src/OpenFOAM/primitives/ints/int32/int32IO.C @@ -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); } diff --git a/src/OpenFOAM/primitives/ints/int64/int64IO.C b/src/OpenFOAM/primitives/ints/int64/int64IO.C index 84bd2a045b2..6cc0b5e0973 100644 --- a/src/OpenFOAM/primitives/ints/int64/int64IO.C +++ b/src/OpenFOAM/primitives/ints/int64/int64IO.C @@ -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); } -- GitLab