Fix 11162: FP: knownConditionTrueFalse (#4254)

* Fix 11162: FP: knownConditionTrueFalse

* Format
This commit is contained in:
Paul Fultz II 2022-07-08 17:57:25 -05:00 committed by GitHub
parent b51aea5531
commit 0b63e7273d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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()) {

View File

@ -6266,6 +6266,14 @@ private:
" v.size();\n"
"}";
ASSERT_EQUALS("", isKnownContainerSizeValue(tokenValues(code, "v . size"), 3));
code = "int f() {\n"
" std::vector<std::vector<int>> 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() {