Fix #11404 FP knownConditionTrueFalse with iterator (#4619)

* Fix wrong value set in valueFlowSameExpressions()

* Fix  #11404 FP knownConditionTrueFalse with iterator
This commit is contained in:
chrchr-github 2022-12-08 10:40:55 +01:00 committed by GitHub
parent 663a8411dd
commit 04b7c0c200
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 4 deletions

View File

@ -2735,8 +2735,13 @@ bool isExpressionChanged(const Token* expr, const Token* start, const Token* end
if (tok->exprId() > 0) { if (tok->exprId() > 0) {
for (const Token* tok2 = start; tok2 != end; tok2 = tok2->next()) { for (const Token* tok2 = start; tok2 != end; tok2 = tok2->next()) {
if (isExpressionChangedAt( int indirect = 0;
tok, tok2, tok->valueType() ? tok->valueType()->pointer : 0, global, settings, cpp, depth)) if (const ValueType* vt = tok->valueType()) {
indirect = vt->pointer;
if (vt->type == ValueType::ITERATOR)
++indirect;
}
if (isExpressionChangedAt(tok, tok2, indirect, global, settings, cpp, depth))
return true; return true;
} }
} }

View File

@ -2440,8 +2440,11 @@ struct ValueFlowAnalyzer : Analyzer {
// TODO: Check if modified in the lambda function // TODO: Check if modified in the lambda function
return Action::Invalid; return Action::Invalid;
int indirect = 0; int indirect = 0;
if (tok->valueType()) if (const ValueType* vt = tok->valueType()) {
indirect = tok->valueType()->pointer; indirect = vt->pointer;
if (vt->type == ValueType::ITERATOR)
++indirect;
}
if (isVariableChanged(tok, indirect, getSettings(), isCPP())) if (isVariableChanged(tok, indirect, getSettings(), isCPP()))
return Action::Invalid; return Action::Invalid;
return Action::None; return Action::None;

View File

@ -4628,6 +4628,18 @@ private:
" if (!std::isalnum(c)) {}\n" " if (!std::isalnum(c)) {}\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("struct S {\n" // #11404
" int f() const;\n"
" void g();\n"
"};\n"
"void h(std::vector<S*>::iterator it) {\n"
" auto i = (*it)->f();\n"
" (*it)->g();\n"
" auto j = (*it)->f();\n"
" if (i == j) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void alwaysTrueInfer() { void alwaysTrueInfer() {