diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index effb2d539..96793402b 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -663,7 +663,7 @@ static void setTokenValue(Token* tok, ValueFlow::Value value, const Settings* se if (std::find(values.begin(), values.end(), value) != values.end()) setTokenValue(parent, value, settings); } - } else { + } else if (!value.isImpossible()) { // is condition only depending on 1 variable? nonneg int varId = 0; bool ret = false; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index f89000607..38a486cd2 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -3223,6 +3223,14 @@ private: "}"; ASSERT_EQUALS(false, testValueOfX(code, 4U, 13)); ASSERT_EQUALS(true, testValueOfX(code, 4U, 26)); + + code = "void f(int* i) {\n" + " if (!i) return;\n" + " int * x = *i == 1 ? i : nullptr;\n" + " int* a = x;\n" + "}\n"; + ASSERT_EQUALS(true, testValueOfX(code, 4U, 0)); + ASSERT_EQUALS(false, testValueOfXImpossible(code, 4U, 0)); } void valueFlowForwardLambda() {