diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 1f8a18502..15ae03644 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -60,7 +60,7 @@ static bool isArrayArg(const Token *tok) static bool isArrayVar(const Token *tok) { const Variable *var = tok->variable(); - return (var && var->isArray()); + return (var && var->isArray() && !var->isArgument()); } static bool isRefPtrArg(const Token *tok) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 09a9bb271..fd1a10dfc 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -79,6 +79,7 @@ private: TEST_CASE(testautovar_extern); TEST_CASE(testautovar_reassigned); TEST_CASE(testinvaliddealloc); + TEST_CASE(testinvaliddealloc_input); // Ticket #10600 TEST_CASE(testinvaliddealloc_string); TEST_CASE(testinvaliddealloc_C); TEST_CASE(testassign1); // Ticket #1819 @@ -764,6 +765,33 @@ private: ASSERT_EQUALS("", errout.str()); } + void testinvaliddealloc_input() { + // #10600 + check("void f(int* a[]) {\n" + " free(a);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + check("void f(int a[]) {\n" + " free(a);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + check("void f(int* a[]) {\n" + " int * p = *a;\n" + " free(p);\n" + " int ** q = a;\n" + " free(q);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + check("void f(int a[]) {\n" + " int * p = a;\n" + " free(p);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void testinvaliddealloc_string() { // #7341 check("void f() {\n"