diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 8b10c6ba2..c0ed8f2ef 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4232,7 +4232,10 @@ struct ValueFlowConditionHandler { // TODO: constValue could be true if there are no assignments in the conditional blocks and // perhaps if there are no && and no || in the condition bool constValue = false; - forward(after, top->scope()->bodyEnd, cond.vartok, values, constValue); + const Scope* scope = top->scope(); + while(scope->nestedIn && scope->type != Scope::eFunction) + scope = scope->nestedIn; + forward(after, scope->bodyEnd, cond.vartok, values, constValue); } } } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index a6f496127..c27b785cc 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -262,7 +262,7 @@ private: " }\n" " tok->str();\n" "}\n"); - TODO_ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (warning, inconclusive) Possible null pointer dereference: tok - otherwise it is redundant to check it against null.\n", "", errout.str()); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok.\n", errout.str()); check("int foo(const Token *tok)\n" "{\n"