Commit 59bdc08c authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: remove FULLDEBUG output on readLabel, readScalar

- used in various places to test if the input can be parsed as a
  label/scalar, so warnings tend to flood the output.

- be more explicit when encountering range errors
parent 98851e9e
......@@ -55,6 +55,7 @@ unsigned testParsing
)
{
unsigned nFail = 0;
string errMsg;
// Expect some failures
const bool prev = FatalIOError.throwExceptions();
......@@ -74,6 +75,7 @@ unsigned testParsing
catch (Foam::error& err)
{
parsed = false;
errMsg = err.message();
}
if (parsed)
......@@ -93,12 +95,15 @@ unsigned testParsing
if (expected)
{
++nFail;
Info<< "(fail) unexpected failure " << str << nl;
Info<< "(fail) unexpected";
}
else
{
Info<< "(pass) expected failure " << str << nl;
Info<< "(pass) expected";
}
Info<< " failure " << str
<< " >> " << errMsg.c_str() << nl;
}
}
......@@ -125,6 +130,7 @@ int main(int argc, char *argv[])
{ " 1234E junk", false },
{ " 3.14159 ", true },
{ " 31.4159E-1 " , true },
{ " 100E1000 " , false },
}
);
}
......@@ -165,6 +171,7 @@ int main(int argc, char *argv[])
&readInt32,
{
{ " 3.14159 ", false },
{ " 31E1 ", false },
{ " 31.4159E-1 " , false },
{ "100" , true },
{ " 2147483644" , true },
......@@ -174,13 +181,16 @@ int main(int argc, char *argv[])
}
{
Info<< nl << "Test readUint32 (max= " << INT32_MAX << "):" << nl;
Info<< nl << "Test readUint32 (max= "
<< unsigned(UINT32_MAX) << "):" << nl;
nFail += testParsing
(
&readUint32,
{
{ " 2147483644" , true },
{ " 2147483700 " , true },
{ " 4294967295 " , true },
{ " 4294968000 " , false },
}
);
}
......
......@@ -102,18 +102,7 @@ bool readScalar(const char* buf, Scalar& val)
val = ScalarConvert(buf, &endptr);
const parsing::errorType err = parsing::checkConversion(buf, endptr);
if (err != parsing::errorType::NONE)
{
#ifdef FULLDEBUG
IOWarningInFunction("unknown")
<< parsing::errorNames[err] << " '" << buf << "'"
<< endl;
#endif
return false;
}
return true;
return (parsing::checkConversion(buf, endptr) == parsing::errorType::NONE);
}
......
......@@ -39,13 +39,13 @@ int Foam::readInt(const char* buf)
const int val = int(parsed);
if (parsed < INT_MIN || parsed > INT_MAX)
{
// Range error
errno = ERANGE;
}
const parsing::errorType err =
(
(parsed < INT_MIN || parsed > INT_MAX)
? parsing::errorType::RANGE
: parsing::checkConversion(buf, endptr)
);
const parsing::errorType err = parsing::checkConversion(buf, endptr);
if (err != parsing::errorType::NONE)
{
FatalIOErrorInFunction("unknown")
......@@ -65,24 +65,12 @@ bool Foam::readInt(const char* buf, int& val)
val = int(parsed);
if (parsed < INT_MIN || parsed > INT_MAX)
{
// Range error
errno = ERANGE;
}
const parsing::errorType err = parsing::checkConversion(buf, endptr);
if (err != parsing::errorType::NONE)
{
#ifdef FULLDEBUG
IOWarningInFunction("unknown")
<< parsing::errorNames[err] << " '" << buf << "'"
<< endl;
#endif
return false;
}
return true;
return
(
(parsed < INT_MIN || parsed > INT_MAX)
? false
: (parsing::checkConversion(buf, endptr) == parsing::errorType::NONE)
);
}
......
......@@ -39,13 +39,13 @@ int32_t Foam::readInt32(const char* buf)
const int32_t val = int32_t(parsed);
if (parsed < INT32_MIN || parsed > INT32_MAX)
{
// Range error
errno = ERANGE;
}
const parsing::errorType err =
(
(parsed < INT32_MIN || parsed > INT32_MAX)
? parsing::errorType::RANGE
: parsing::checkConversion(buf, endptr)
);
const parsing::errorType err = parsing::checkConversion(buf, endptr);
if (err != parsing::errorType::NONE)
{
FatalIOErrorInFunction("unknown")
......@@ -65,24 +65,12 @@ bool Foam::readInt32(const char* buf, int32_t& val)
val = int32_t(parsed);
if (parsed < INT32_MIN || parsed > INT32_MAX)
{
// Range error
errno = ERANGE;
}
const parsing::errorType err = parsing::checkConversion(buf, endptr);
if (err != parsing::errorType::NONE)
{
#ifdef FULLDEBUG
IOWarningInFunction("unknown")
<< parsing::errorNames[err] << " '" << buf << "'"
<< endl;
#endif
return false;
}
return true;
return
(
(parsed < INT32_MIN || parsed > INT32_MAX)
? false
: (parsing::checkConversion(buf, endptr) == parsing::errorType::NONE)
);
}
......
......@@ -39,13 +39,13 @@ int64_t Foam::readInt64(const char* buf)
const int64_t val = int64_t(parsed);
if (parsed < INT64_MIN || parsed > INT64_MAX)
{
// Range error
errno = ERANGE;
}
const parsing::errorType err =
(
(parsed < INT64_MIN || parsed > INT64_MAX)
? parsing::errorType::RANGE
: parsing::checkConversion(buf, endptr)
);
const parsing::errorType err = parsing::checkConversion(buf, endptr);
if (err != parsing::errorType::NONE)
{
FatalIOErrorInFunction("unknown")
......@@ -65,24 +65,12 @@ bool Foam::readInt64(const char* buf, int64_t& val)
val = int64_t(parsed);
if (parsed < INT64_MIN || parsed > INT64_MAX)
{
// Range error
errno = ERANGE;
}
const parsing::errorType err = parsing::checkConversion(buf, endptr);
if (err != parsing::errorType::NONE)
{
#ifdef FULLDEBUG
IOWarningInFunction("unknown")
<< parsing::errorNames[err] << " '" << buf << "'"
<< endl;
#endif
return false;
}
return true;
return
(
(parsed < INT64_MIN || parsed > INT64_MAX)
? false
: (parsing::checkConversion(buf, endptr) == parsing::errorType::NONE)
);
}
......
......@@ -38,13 +38,13 @@ uint32_t Foam::readUint32(const char* buf)
const uint32_t val = uint32_t(parsed);
if (parsed > UINT32_MAX)
{
// Range error
errno = ERANGE;
}
const parsing::errorType err =
(
(parsed > UINT32_MAX)
? parsing::errorType::RANGE
: parsing::checkConversion(buf, endptr)
);
const parsing::errorType err = parsing::checkConversion(buf, endptr);
if (err != parsing::errorType::NONE)
{
FatalIOErrorInFunction("unknown")
......@@ -64,24 +64,12 @@ bool Foam::readUint32(const char* buf, uint32_t& val)
val = uint32_t(parsed);
if (parsed > UINT32_MAX)
{
// Range error
errno = ERANGE;
}
const parsing::errorType err = parsing::checkConversion(buf, endptr);
if (err != parsing::errorType::NONE)
{
#ifdef FULLDEBUG
IOWarningInFunction("unknown")
<< parsing::errorNames[err] << " '" << buf << "'"
<< endl;
#endif
return false;
}
return true;
return
(
(parsed > UINT32_MAX)
? false
: (parsing::checkConversion(buf, endptr) == parsing::errorType::NONE)
);
}
......
......@@ -38,13 +38,13 @@ uint64_t Foam::readUint64(const char* buf)
const uint64_t val = uint64_t(parsed);
if (parsed > UINT64_MAX)
{
// Range error
errno = ERANGE;
}
const parsing::errorType err =
(
(parsed > UINT64_MAX)
? parsing::errorType::RANGE
: parsing::checkConversion(buf, endptr)
);
const parsing::errorType err = parsing::checkConversion(buf, endptr);
if (err != parsing::errorType::NONE)
{
FatalIOErrorInFunction("unknown")
......@@ -64,24 +64,12 @@ bool Foam::readUint64(const char* buf, uint64_t& val)
val = uint64_t(parsed);
if (parsed > UINT64_MAX)
{
// Range error
errno = ERANGE;
}
const parsing::errorType err = parsing::checkConversion(buf, endptr);
if (err != parsing::errorType::NONE)
{
#ifdef FULLDEBUG
IOWarningInFunction("unknown")
<< parsing::errorNames[err] << " '" << buf << "'"
<< endl;
#endif
return false;
}
return true;
return
(
(parsed > UINT64_MAX)
? false
: (parsing::checkConversion(buf, endptr) == parsing::errorType::NONE)
);
}
......
......@@ -30,7 +30,8 @@ License
const Foam::Enum<Foam::parsing::errorType>
Foam::parsing::errorNames
{
{ errorType::GENERAL, "General error parsing" },
{ errorType::GENERAL, "General error parsing" },
{ errorType::RANGE, "Range error while parsing" },
{ errorType::TRAILING, "Trailing content found parsing" },
};
......
......@@ -56,7 +56,8 @@ namespace parsing
{
NONE = 0, //!< No error encountered
GENERAL = 1, //!< General parsing error
TRAILING = 2, //!< Trailing content detected
RANGE = 2, //!< Range error
TRAILING = 3, //!< Trailing content detected
};
......
......@@ -32,7 +32,7 @@ inline Foam::parsing::errorType Foam::parsing::checkConversion
if (errno || endptr == buf)
{
// Some type of error OR no conversion
return errorType::GENERAL;
return (errno == ERANGE ? errorType::RANGE : errorType::GENERAL);
}
// Trailing spaces are permitted
......
Markdown is supported
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