Check for additional invalid string-to-double conversions
This commit is contained in:
parent
3e9b0e0c07
commit
84535483f9
2 changed files with 28 additions and 0 deletions
|
|
@ -147,6 +147,9 @@ doublereal fpValueCheck(const std::string& val)
|
|||
int istart = 0;
|
||||
ch = str[0];
|
||||
if (ch == '+' || ch == '-') {
|
||||
if (str.size() == 1) {
|
||||
throw CanteraError("fpValueCheck", "string ends in '{}'", ch);
|
||||
}
|
||||
istart = 1;
|
||||
}
|
||||
for (size_t i = istart; i < str.size(); i++) {
|
||||
|
|
@ -168,9 +171,16 @@ doublereal fpValueCheck(const std::string& val)
|
|||
if (numExp > 1) {
|
||||
throw CanteraError("fpValueCheck",
|
||||
"string has more than one exp char");
|
||||
} else if (i == str.size() - 1) {
|
||||
throw CanteraError("fpValueCheck",
|
||||
"string ends in '{}'", ch);
|
||||
}
|
||||
ch = str[i+1];
|
||||
if (ch == '+' || ch == '-') {
|
||||
if (i + 1 == str.size() - 1) {
|
||||
throw CanteraError("fpValueCheck",
|
||||
"string ends in '{}'", ch);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -81,6 +81,24 @@ TEST(parseCompString, not_a_number)
|
|||
CanteraError);
|
||||
}
|
||||
|
||||
TEST(parseCompString, not_a_number2)
|
||||
{
|
||||
ASSERT_THROW(parseCompString("foo:1.0 bar:1e- baz:1e-4"),
|
||||
CanteraError);
|
||||
}
|
||||
|
||||
TEST(parseCompString, not_a_number3)
|
||||
{
|
||||
ASSERT_THROW(parseCompString("foo:1.0 bar:1.2e baz:1e-4"),
|
||||
CanteraError);
|
||||
}
|
||||
|
||||
TEST(parseCompString, not_a_number4)
|
||||
{
|
||||
ASSERT_THROW(parseCompString("foo:1.0 bar:+ baz:1e-4"),
|
||||
CanteraError);
|
||||
}
|
||||
|
||||
TEST(parseCompString, missing_value)
|
||||
{
|
||||
ASSERT_THROW(parseCompString("foo:1.0 bar: baz:1e-4"),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue