From 0b63e7273d76607f8bedb77bfa869509234f1257 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Fri, 8 Jul 2022 17:57:25 -0500 Subject: [PATCH] Fix 11162: FP: knownConditionTrueFalse (#4254) * Fix 11162: FP: knownConditionTrueFalse * Format --- lib/valueflow.cpp | 2 +- test/testvalueflow.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index fd470ba3a..054348037 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -684,7 +684,7 @@ static void setTokenValue(Token* tok, return; } - if (value.isContainerSizeValue()) { + if (value.isContainerSizeValue() && astIsContainer(tok)) { // .empty, .size, +"abc", +'a' if (Token::Match(parent, "+|==|!=") && parent->astOperand1() && parent->astOperand2()) { for (const ValueFlow::Value &value1 : parent->astOperand1()->values()) { diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 27c06d438..4bd7b27c5 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -6266,6 +6266,14 @@ private: " v.size();\n" "}"; ASSERT_EQUALS("", isKnownContainerSizeValue(tokenValues(code, "v . size"), 3)); + + code = "int f() {\n" + " std::vector> v;\n" + " auto it = v.begin();\n" + " auto x = it->size();\n" + " return x;\n" + "}\n"; + ASSERT_EQUALS(false, testValueOfX(code, 5U, 0)); } void valueFlowDynamicBufferSize() {