From 36e663e25013509e0e423152fbc6f561a5c2001f Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Thu, 8 Nov 2018 23:09:51 -0600 Subject: [PATCH] Fix issue 8839: FP knownConditionTrueFalse - condition inside a while-clause (#1469) --- lib/valueflow.cpp | 1 + test/testcondition.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 1e51faffc..54d9eeef6 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1145,6 +1145,7 @@ static void valueFlowTerminatingCondition(TokenList *tokenlist, SymbolDatabase* const Scope * condScope = nullptr; for(const Scope * parent = condTok->scope();parent;parent = parent->nestedIn) { if (parent->type == Scope::eIf || + parent->type == Scope::eWhile || parent->type == Scope::eSwitch) { condScope = parent; break; diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 7492211e9..b2a24efc3 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -2673,6 +2673,16 @@ private: " return std::time(0) > maxtime;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void foo(double param) {\n" + " while(bar()) {\n" + " if (param<0.)\n" + " return;\n" + " }\n" + " if (param<0.)\n" + " return;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void multiConditionAlwaysTrue() {