Fix #12252 Regression: constParameterPointer (#5819)

This commit is contained in:
chrchr-github 2024-01-02 20:07:35 +01:00 committed by GitHub
parent 14627ca6d2
commit 8d64d12e5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -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 (val.isLocalLifetimeValue() || (pointer && val.isSymbolicValue() && val.intvalue == 0)) {
if (findAstNode(val.tokvalue, if (findAstNode(val.tokvalue,
[&](const Token* aliasTok) { [&](const Token* aliasTok) {
return aliasTok->exprId() == childTok->exprId(); return aliasTok != childTok && aliasTok->exprId() == childTok->exprId();
})) { })) {
if (val.isInconclusive() && inconclusive != nullptr) { if (val.isInconclusive() && inconclusive != nullptr) {
value = &val; value = &val;

View File

@ -3991,6 +3991,15 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 's' can be declared as pointer to const\n", ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 's' can be declared as pointer to const\n",
errout.str()); 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() { void switchRedundantAssignmentTest() {