diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 74de5af16..a3fa9957b 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1136,6 +1136,8 @@ static void valueFlowTerminatingCondition(TokenList *tokenlist, SymbolDatabase* const Variable * var = tok2->variable(); if (!var) continue; + if(!var->scope()) + continue; const Token * endToken = var->scope()->bodyEnd; if (!var->isLocal() && !var->isConst() && !var->isArgument()) { bail = true; diff --git a/test/testcondition.cpp b/test/testcondition.cpp index cf4104b4e..318959a86 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -2693,6 +2693,16 @@ private: " return;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // 8842 crash + check("class a {\n" + " int b;\n" + " c(b);\n" + " void f() {\n" + " if (b) return;\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); } void multiConditionAlwaysTrue() {