Fixed #4141 (Crash when parsing divide by zero.)
This commit is contained in:
parent
107b3b4401
commit
511c5a62e7
|
@ -7049,29 +7049,7 @@ public:
|
|||
}
|
||||
|
||||
// Simplify calculations..
|
||||
while (Token::Match(start, "%num% %op% %num% %op%") &&
|
||||
start->strAt(1) == start->strAt(3)) {
|
||||
const std::string &op = start->strAt(1);
|
||||
if (op.size() != 1U)
|
||||
break;
|
||||
const std::string &val1 = start->str();
|
||||
const std::string &val2 = start->strAt(2);
|
||||
const std::string result = MathLib::calculate(val1, val2, op[0]);
|
||||
start->str(result);
|
||||
start->deleteNext(2);
|
||||
}
|
||||
if (Token::Match(start, "%num% %op% %num% [,}]")) {
|
||||
const std::string &op = start->strAt(1);
|
||||
if (op.size() == 1U) {
|
||||
const std::string &val1 = start->str();
|
||||
const std::string &val2 = start->strAt(2);
|
||||
const std::string result = MathLib::calculate(val1, val2, op[0]);
|
||||
start->str(result);
|
||||
start->deleteNext(2);
|
||||
value = start;
|
||||
start = end = 0;
|
||||
}
|
||||
}
|
||||
while (start && start->previous() && TemplateSimplifier::simplifyNumericCalculations(start->previous())) { }
|
||||
}
|
||||
|
||||
Token *name;
|
||||
|
|
|
@ -355,6 +355,7 @@ private:
|
|||
TEST_CASE(enum31); // ticket #3934 (calculation in first item)
|
||||
TEST_CASE(enum32); // ticket #3998 (access violation)
|
||||
TEST_CASE(enum33); // ticket #4015 (segmentation fault)
|
||||
TEST_CASE(enum34); // ticket #4141 (division by zero)
|
||||
TEST_CASE(enumscope1); // ticket #3949
|
||||
|
||||
// remove "std::" on some standard functions
|
||||
|
@ -7150,7 +7151,7 @@ private:
|
|||
|
||||
void enum29() { // #3747 - bitwise or value
|
||||
const char code[] = "enum { x=1, y=x|2 }; i = (3==y);";
|
||||
ASSERT_EQUALS("i = 3 == 3 ;", checkSimplifyEnum(code));
|
||||
ASSERT_EQUALS("i = 3 == 1 | 2 ;", checkSimplifyEnum(code));
|
||||
}
|
||||
|
||||
void enum30() { // #3852 - false positive
|
||||
|
@ -7188,6 +7189,11 @@ private:
|
|||
ASSERT_EQUALS(";", checkSimplifyEnum(code));
|
||||
}
|
||||
|
||||
void enum34() { // #4141 - division by zero
|
||||
const char code[] = "enum { A=1/0 };";
|
||||
ASSERT_EQUALS(";", checkSimplifyEnum(code));
|
||||
}
|
||||
|
||||
void enumscope1() { // #3949 - don't simplify enum from one function in another function
|
||||
const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n"
|
||||
"void bar() { int a = A; }";
|
||||
|
|
Loading…
Reference in New Issue