diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 83a71cb11..38d560817 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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)) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 3fbfc30eb..18029fb10 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -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; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index e62206bf4..5716741d2 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -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() {