Skip to content

Commit 04b7c0c

Browse files
Fix #11404 FP knownConditionTrueFalse with iterator (#4619)
* Fix wrong value set in valueFlowSameExpressions() * Fix #11404 FP knownConditionTrueFalse with iterator
1 parent 663a841 commit 04b7c0c

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

lib/astutils.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,8 +2735,13 @@ bool isExpressionChanged(const Token* expr, const Token* start, const Token* end
27352735

27362736
if (tok->exprId() > 0) {
27372737
for (const Token* tok2 = start; tok2 != end; tok2 = tok2->next()) {
2738-
if (isExpressionChangedAt(
2739-
tok, tok2, tok->valueType() ? tok->valueType()->pointer : 0, global, settings, cpp, depth))
2738+
int indirect = 0;
2739+
if (const ValueType* vt = tok->valueType()) {
2740+
indirect = vt->pointer;
2741+
if (vt->type == ValueType::ITERATOR)
2742+
++indirect;
2743+
}
2744+
if (isExpressionChangedAt(tok, tok2, indirect, global, settings, cpp, depth))
27402745
return true;
27412746
}
27422747
}

lib/valueflow.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,8 +2440,11 @@ struct ValueFlowAnalyzer : Analyzer {
24402440
// TODO: Check if modified in the lambda function
24412441
return Action::Invalid;
24422442
int indirect = 0;
2443-
if (tok->valueType())
2444-
indirect = tok->valueType()->pointer;
2443+
if (const ValueType* vt = tok->valueType()) {
2444+
indirect = vt->pointer;
2445+
if (vt->type == ValueType::ITERATOR)
2446+
++indirect;
2447+
}
24452448
if (isVariableChanged(tok, indirect, getSettings(), isCPP()))
24462449
return Action::Invalid;
24472450
return Action::None;

test/testcondition.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4628,6 +4628,18 @@ class TestCondition : public TestFixture {
46284628
" if (!std::isalnum(c)) {}\n"
46294629
"}\n");
46304630
ASSERT_EQUALS("", errout.str());
4631+
4632+
check("struct S {\n" // #11404
4633+
" int f() const;\n"
4634+
" void g();\n"
4635+
"};\n"
4636+
"void h(std::vector<S*>::iterator it) {\n"
4637+
" auto i = (*it)->f();\n"
4638+
" (*it)->g();\n"
4639+
" auto j = (*it)->f();\n"
4640+
" if (i == j) {}\n"
4641+
"}\n");
4642+
ASSERT_EQUALS("", errout.str());
46314643
}
46324644

46334645
void alwaysTrueInfer() {

0 commit comments

Comments
 (0)