ValueFlow: Dont try to evaluate '/=0;'
This commit is contained in:
parent
7fba6ecef1
commit
f10634c021
|
@ -1684,17 +1684,24 @@ static bool valueFlowForward(Token * const startToken,
|
||||||
// Erase values that are not int values..
|
// Erase values that are not int values..
|
||||||
for (it = values.begin(); it != values.end();) {
|
for (it = values.begin(); it != values.end();) {
|
||||||
if (it->isIntValue()) {
|
if (it->isIntValue()) {
|
||||||
|
bool ub = false;
|
||||||
if (assign == "+=")
|
if (assign == "+=")
|
||||||
it->intvalue += rhsValue.intvalue;
|
it->intvalue += rhsValue.intvalue;
|
||||||
else if (assign == "-=")
|
else if (assign == "-=")
|
||||||
it->intvalue -= rhsValue.intvalue;
|
it->intvalue -= rhsValue.intvalue;
|
||||||
else if (assign == "*=")
|
else if (assign == "*=")
|
||||||
it->intvalue *= rhsValue.intvalue;
|
it->intvalue *= rhsValue.intvalue;
|
||||||
else if (assign == "/=")
|
else if (assign == "/=") {
|
||||||
it->intvalue /= rhsValue.intvalue;
|
if (rhsValue.intvalue == 0)
|
||||||
else if (assign == "%=")
|
ub = true;
|
||||||
it->intvalue %= rhsValue.intvalue;
|
else
|
||||||
else if (assign == "&=")
|
it->intvalue /= rhsValue.intvalue;
|
||||||
|
} else if (assign == "%=") {
|
||||||
|
if (rhsValue.intvalue == 0)
|
||||||
|
ub = true;
|
||||||
|
else
|
||||||
|
it->intvalue %= rhsValue.intvalue;
|
||||||
|
} else if (assign == "&=")
|
||||||
it->intvalue &= rhsValue.intvalue;
|
it->intvalue &= rhsValue.intvalue;
|
||||||
else if (assign == "|=")
|
else if (assign == "|=")
|
||||||
it->intvalue |= rhsValue.intvalue;
|
it->intvalue |= rhsValue.intvalue;
|
||||||
|
@ -1704,7 +1711,10 @@ static bool valueFlowForward(Token * const startToken,
|
||||||
values.clear();
|
values.clear();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++it;
|
if (ub)
|
||||||
|
it = values.erase(it);
|
||||||
|
else
|
||||||
|
++it;
|
||||||
} else if (it->isFloatValue()) {
|
} else if (it->isFloatValue()) {
|
||||||
if (assign == "+=")
|
if (assign == "+=")
|
||||||
it->floatValue += rhsValue.intvalue;
|
it->floatValue += rhsValue.intvalue;
|
||||||
|
|
|
@ -1746,6 +1746,13 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 4U, 166));
|
ASSERT_EQUALS(true, testValueOfX(code, 4U, 166));
|
||||||
|
|
||||||
|
code = "void f() {\n"
|
||||||
|
" int x = 123;\n"
|
||||||
|
" x /= 0;\n" // don't crash when evaluating x/=0
|
||||||
|
" return x;\n"
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS(false, testValueOfX(code, 4U, 123));
|
||||||
|
|
||||||
code = "void f() {\n"
|
code = "void f() {\n"
|
||||||
" float x = 123.45;\n"
|
" float x = 123.45;\n"
|
||||||
" x += 67;\n"
|
" x += 67;\n"
|
||||||
|
|
Loading…
Reference in New Issue