Fixed #8784 (False positive uninitialized variable)
This commit is contained in:
parent
68ea60d207
commit
e50b9e2bef
|
@ -2869,6 +2869,15 @@ static bool valueFlowForwardVariable(Token* const startToken,
|
|||
if (isVariableChangedByFunctionCall(expr, 1, varid, settings, nullptr))
|
||||
lowerToPossible(values, 1);
|
||||
} else {
|
||||
if (number_of_if >= 1) {
|
||||
// is variable used in conditional code? the value is not known
|
||||
if (settings->debugwarnings)
|
||||
bailout(tokenlist,
|
||||
errorLogger,
|
||||
tok2,
|
||||
"variable " + var->name() + " valueFlowForwardVariable, number_of_if");
|
||||
return false;
|
||||
}
|
||||
for (const ValueFlow::Value &v : values) {
|
||||
const ProgramMemory programMemory(getProgramMemory(tok2, varid, v));
|
||||
if (conditionIsTrue(condition, programMemory))
|
||||
|
|
|
@ -1276,7 +1276,7 @@ private:
|
|||
" if (x) p = q;\n"
|
||||
" if (y ? p->x : p->y) { }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Possible null pointer dereference: p\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (warning) Possible null pointer dereference: p\n", "", errout.str());
|
||||
}
|
||||
|
||||
void nullpointer21() { // #4038 - fp: if (x) p=q; else return;
|
||||
|
|
|
@ -2535,6 +2535,14 @@ private:
|
|||
" x = *p ? : 1;\n" // <- no explicit expr0
|
||||
"}";
|
||||
testValueOfX(code, 1U, 0); // do not crash
|
||||
|
||||
code = "void f(int a) {\n" // #8784
|
||||
" int x = 13;\n"
|
||||
" if (a == 1) x = 26;\n"
|
||||
" return a == 1 ? x : 0;\n" // <- x is 26
|
||||
"}";
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 4U, 13));
|
||||
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 4U, 26));
|
||||
}
|
||||
|
||||
void valueFlowForwardLambda() {
|
||||
|
|
Loading…
Reference in New Issue