From 33ec78fe6e2a0da56e871464f96578819cb134e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 20 Dec 2019 19:06:35 +0100 Subject: [PATCH] Fixed #9036 (false positive: (style) Condition 's.x<127U' is always true) --- lib/valueflow.cpp | 2 ++ test/testvalueflow.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 7aeaa6ddc..75624c3f8 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5779,6 +5779,8 @@ static void valueFlowContainerAfterCondition(TokenList *tokenlist, static void valueFlowFwdAnalysis(const TokenList *tokenlist, const Settings *settings) { for (const Token *tok = tokenlist->front(); tok; tok = tok->next()) { + if (Token::simpleMatch(tok, "for (")) + tok = tok->linkAt(1); if (tok->str() != "=" || !tok->astOperand1() || !tok->astOperand2()) continue; if (!tok->scope()->isExecutable()) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index aa2bde69e..7d1f238fa 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -2762,6 +2762,14 @@ private: "}"; values = tokenValues(code, "=="); ASSERT_EQUALS(true, values.empty()); + + // for loops + code = "struct S { int x; };\n" // #9036 + "void foo(struct S s) {\n" + " for (s.x = 0; s.x < 127; s.x++) {}\n" + "}"; + values = tokenValues(code, "<"); // TODO: comparison can be true or false + ASSERT_EQUALS(true, values.empty()); } void valueFlowSwitchVariable() {