Partial fix for 12031: False positive: uninitialized variable (#5573)
This commit is contained in:
parent
09f426d980
commit
e1a120e6b0
|
@ -204,8 +204,10 @@ static bool evaluateCondition(const std::string& op,
|
||||||
if (!condition)
|
if (!condition)
|
||||||
return false;
|
return false;
|
||||||
if (condition->str() == op) {
|
if (condition->str() == op) {
|
||||||
return evaluateCondition(op, r, condition->astOperand1(), pm, settings) ||
|
if (evaluateCondition(op, r, condition->astOperand1(), pm, settings) ||
|
||||||
evaluateCondition(op, r, condition->astOperand2(), pm, settings);
|
evaluateCondition(op, r, condition->astOperand2(), pm, settings)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MathLib::bigint result = 0;
|
MathLib::bigint result = 0;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
|
@ -309,8 +311,10 @@ void programMemoryParseCondition(ProgramMemory& pm, const Token* tok, const Toke
|
||||||
if (lhs.empty() || rhs.empty()) {
|
if (lhs.empty() || rhs.empty()) {
|
||||||
if (frontIs(lhs, !then))
|
if (frontIs(lhs, !then))
|
||||||
programMemoryParseCondition(pm, tok->astOperand2(), endTok, settings, then);
|
programMemoryParseCondition(pm, tok->astOperand2(), endTok, settings, then);
|
||||||
if (frontIs(rhs, !then))
|
else if (frontIs(rhs, !then))
|
||||||
programMemoryParseCondition(pm, tok->astOperand1(), endTok, settings, then);
|
programMemoryParseCondition(pm, tok->astOperand1(), endTok, settings, then);
|
||||||
|
else
|
||||||
|
pm.setIntValue(tok, 0, then);
|
||||||
}
|
}
|
||||||
} else if (tok->exprId() > 0) {
|
} else if (tok->exprId() > 0) {
|
||||||
if (endTok && isExpressionChanged(tok, tok->next(), endTok, settings, true))
|
if (endTok && isExpressionChanged(tok, tok->next(), endTok, settings, true))
|
||||||
|
|
|
@ -5605,6 +5605,22 @@ private:
|
||||||
"}\n";
|
"}\n";
|
||||||
values = tokenValues(code, "x >", ValueFlow::Value::ValueType::UNINIT);
|
values = tokenValues(code, "x >", ValueFlow::Value::ValueType::UNINIT);
|
||||||
ASSERT_EQUALS(0, values.size());
|
ASSERT_EQUALS(0, values.size());
|
||||||
|
|
||||||
|
// #12031
|
||||||
|
code = "bool g(int *p);\n"
|
||||||
|
"bool h();\n"
|
||||||
|
"void f(bool b, int y) {\n"
|
||||||
|
" int x;\n"
|
||||||
|
" if (b && y > 0) {\n"
|
||||||
|
" b = g(&x);\n"
|
||||||
|
" }\n"
|
||||||
|
" while (b && y > 0) {\n"
|
||||||
|
" if (x < 0) {}\n"
|
||||||
|
" break;\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n";
|
||||||
|
values = tokenValues(code, "x <", ValueFlow::Value::ValueType::UNINIT);
|
||||||
|
ASSERT_EQUALS(0, values.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueFlowConditionExpressions() {
|
void valueFlowConditionExpressions() {
|
||||||
|
|
Loading…
Reference in New Issue