From 8d64d12e5da20a1ef68a792c69e8aa5c94baecd9 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 2 Jan 2024 20:07:35 +0100 Subject: [PATCH] Fix #12252 Regression: constParameterPointer (#5819) --- lib/astutils.cpp | 2 +- test/testother.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 8db8a56cff1..e31c73fc235 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -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; diff --git a/test/testother.cpp b/test/testother.cpp index 657450c3da3..20228dfa911 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3991,6 +3991,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() {