Repository navigation
Fix #15155 FN accessMoved (string concatenation using +=) #8996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dada503
30484de
5812614
bbbd6e5
28c5e65
811a54c
5ecbfde
a2b79cc
6edbf5f
c0eacdf
8de381b
c3ca0d7
6240b75
1271964
0ea5f5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2646,14 +2646,16 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, | |
| return false; | ||
|
|
||
| const Token *tok2 = tok; | ||
| int derefs = 0; | ||
| int derefs = 0, arrayAccess = 0; | ||
| while ((tok2->astParent() && tok2->astParent()->isUnaryOp("*")) || | ||
| (Token::simpleMatch(tok2->astParent(), ".") && !Token::Match(tok2->astParent()->astParent(), "[(,]")) || | ||
| (tok2->astParent() && tok2->astParent()->isUnaryOp("&") && Token::simpleMatch(tok2->astParent()->astParent(), ".") && tok2->astParent()->astParent()->originalName()=="->") || | ||
| (Token::simpleMatch(tok2->astParent(), "[") && tok2 == tok2->astParent()->astOperand1()) || | ||
| (Token::simpleMatch(tok2->astParent(), "(") && tok2->astParent()->isCast())) { | ||
| if (tok2->astParent() && (tok2->astParent()->isUnaryOp("*") || (astIsLHS(tok2) && tok2->astParent()->originalName() == "->" && !hasOverloadedMemberAccess(tok2)))) | ||
| derefs++; | ||
| if (Token::simpleMatch(tok2->astParent(), "[") && tok2->valueType() && tok2->valueType()->pointer > 0) | ||
| arrayAccess++; | ||
| if (derefs > indirect) | ||
| break; | ||
| if (tok2->astParent() && tok2->astParent()->isUnaryOp("&") && Token::simpleMatch(tok2->astParent()->astParent(), ".") && tok2->astParent()->astParent()->originalName()=="->") | ||
|
|
@@ -2688,7 +2690,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, | |
| }; | ||
| tok2 = skipRedundantPtrOp(tok2, tok2->astParent()); | ||
|
|
||
| if (tok2->astParent() && tok2->astParent()->isAssignmentOp()) { | ||
| if (tok2->astParent() && tok2->astParent()->isAssignmentOp() && (indirect - derefs - arrayAccess <= 0 || tok2->astParent()->str() == "=")) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI review The container-yield branch further down ( void f(std::vector<std::array<int,3>>& v) { auto p = v.data(); p->at(0) += 1; }
void g(std::vector<std::array<int,3>>& v) { auto p = v.data(); (*p).at(0) += 1; }
void h(std::vector<std::string>& v) { auto p = v.data(); p->front() += 1; }pr reports |
||
| if (astIsLHS(tok2)) | ||
| return true; | ||
| // Check if assigning to a non-const lvalue | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI review
Only a
[on an operand withvalueType()->pointer > 0is counted. Iterators havepointer == 0, so for an iterator alias asked withindirect == 1,indirect - derefs - arrayAccessis 1, andit[0] += 1is no longer seen as a change of the element. This is a new false positive compared with base:pr:
Parameter 'v' can be declared as reference to const [constParameterReference]. Base reports nothing, andit[0] = 1gives nothing in pr either. Possible fix: also count[when the operand is an iterator (vt->type == ValueType::ITERATOR), or more generally when the operand is not a container.