From 34330b51d11596b0f9f1a9c1a687aa99ae5b22a8 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Tue, 18 Dec 2018 08:16:43 +0100 Subject: [PATCH] Fix issue 8905: Condition 'a==0' is always false This fixes the FP in: ```cpp void f(const int a[]){ if (a == 0){} } ``` --- lib/valueflow.cpp | 3 ++- test/testcondition.cpp | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 6117cdb05..cbd724915 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1002,7 +1002,8 @@ static void valueFlowArray(TokenList *tokenlist) for (Token *tok = tokenlist->front(); tok; tok = tok->next()) { if (tok->varId() > 0U) { // array - if (tok->variable() && tok->variable()->isArray() && !tok->variable()->isStlType()) { + if (tok->variable() && tok->variable()->isArray() && !tok->variable()->isArgument() && + !tok->variable()->isStlType()) { ValueFlow::Value value{1}; value.setKnown(); setTokenValue(tok, value, tokenlist->getSettings()); diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 8984f282e..9d0cee3ab 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -2715,6 +2715,9 @@ private: " if (!(strcmp(x, y) == 0)) { return; }\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void f(const int a[]){ if (a == 0){} }"); + ASSERT_EQUALS("", errout.str()); } void multiConditionAlwaysTrue() {