`break` if divider `intval` is 0 to avoid division by 0 as suggested by @pfultz2 Trac ticket: https://trac.cppcheck.net/ticket/9510
This commit is contained in:
parent
f637d97080
commit
95e0b0d0f9
|
@ -2990,6 +2990,8 @@ static const Token* solveExprValues(const Token* expr, std::list<ValueFlow::Valu
|
|||
return solveExprValues(binaryTok, values);
|
||||
}
|
||||
case '*': {
|
||||
if (intval == 0)
|
||||
break;
|
||||
transformIntValues(values, [&](MathLib::bigint x) {
|
||||
return x / intval;
|
||||
});
|
||||
|
|
|
@ -130,6 +130,8 @@ private:
|
|||
TEST_CASE(valueFlowPointerAliasDeref);
|
||||
|
||||
TEST_CASE(valueFlowCrashIncompleteCode);
|
||||
|
||||
TEST_CASE(valueFlowCrash);
|
||||
}
|
||||
|
||||
static bool isNotTokValue(const ValueFlow::Value &val) {
|
||||
|
@ -4343,6 +4345,15 @@ private:
|
|||
"}\n";
|
||||
valueOfTok(code, "0");
|
||||
}
|
||||
|
||||
void valueFlowCrash() {
|
||||
const char* code;
|
||||
|
||||
code = "void f(int x) {\n"
|
||||
" if (0 * (x > 2)) {}\n"
|
||||
"}\n";
|
||||
valueOfTok(code, "x");
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestValueFlow)
|
||||
|
|
Loading…
Reference in New Issue