Skip to content
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

Fix #12252 Regression: constParameterPointer #5819

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ bool isAliasOf(const Token* tok, const Token* expr, int* indirect, bool* inconcl
if (val.isLocalLifetimeValue() || (pointer && val.isSymbolicValue() && val.intvalue == 0)) {
if (findAstNode(val.tokvalue,
[&](const Token* aliasTok) {
return aliasTok->exprId() == childTok->exprId();
return aliasTok != childTok && aliasTok->exprId() == childTok->exprId();
})) {
if (val.isInconclusive() && inconclusive != nullptr) {
value = &val;
Expand Down
9 changes: 9 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3973,6 +3973,15 @@ class TestOther : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 's' can be declared as pointer to const\n",
errout.str());

check("void f(char *a1, char *a2) {\n" // #12252
" char* b = new char[strlen(a1) + strlen(a2) + 2];\n"
" sprintf(b, \"%s_%s\", a1, a2);\n"
" delete[] b;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'a1' can be declared as pointer to const\n"
"[test.cpp:1]: (style) Parameter 'a2' can be declared as pointer to const\n",
errout.str());
}

void switchRedundantAssignmentTest() {
Expand Down
Loading