Fix #10600: FP invalid dealloc of function array argument (#3613)

Do not warn for array arguments that are free'd, since they decay to
pointers.
This commit is contained in:
Rikard Falkeborn 2021-12-09 07:16:40 +01:00 committed by GitHub
parent bca27bf7d2
commit e7b6920cf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -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)

View File

@ -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"