From ef4a7ba7f2dbe4a08419f193bed1900687ef08e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 3 Sep 2017 14:46:37 +0200 Subject: [PATCH] Fix FP in CheckCondition::multiCondition2 --- lib/checkcondition.cpp | 2 +- test/testcondition.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 18fa4e0ee..27999245a 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -491,7 +491,7 @@ void CheckCondition::multiCondition2() nonlocal |= (var && (var->isPointer() || var->isReference())); } else if (!nonlocal && cond->isName()) { // varid is 0. this is possibly a nonlocal variable.. - nonlocal = Token::Match(cond->astParent(), "%cop%|("); + nonlocal = Token::Match(cond->astParent(), "%cop%|(|["); } else { tokens.push(cond->astOperand1()); tokens.push(cond->astOperand2()); diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 7ad2ba401..8cce0d1e6 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -1532,6 +1532,15 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + // undeclared array + check("void f(int x) {\n" + " if (a[x] > 0) {\n" + " a[x] -= dt;\n" + " if (a[x] < 0) {}\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // #6313 - false positive: opposite conditions in nested if blocks when condition changed check("void Foo::Bar() {\n" " if(var){\n"