From 07d8cb4f01b1eabbe7db45b0e44be7f43dffbdc8 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 29 Jun 2020 11:55:59 -0500 Subject: [PATCH] Extend scope of afterCondition until end of function --- lib/valueflow.cpp | 5 ++++- test/testnullpointer.cpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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"