From ea23a0467bc522f02a4a7d4afd024f3547d8658a Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 27 Apr 2014 10:56:55 +0200 Subject: [PATCH] Fixed false positive #5732: autovarInvalidDeallocation on pointer to array --- lib/checkautovariables.cpp | 2 +- test/testautovariables.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 95cf3d4f4..144f2866a 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -78,7 +78,7 @@ bool CheckAutoVariables::isAutoVarArray(const Token *tok) { const Variable *var = tok->variable(); - return (var && var->isLocal() && !var->isStatic() && var->isArray()); + return (var && var->isLocal() && !var->isStatic() && var->isArray() && !var->isPointer()); } // Verification that we really take the address of a local variable diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index f7151c371..fa476ced7 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -501,6 +501,18 @@ private: "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout.str()); + // #5732 + check("int main() {\n" + " long (*pKoeff)[256] = new long[9][256];\n" + " delete[] pKoeff;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + check("int main() {\n" + " long *pKoeff[256];\n" + " delete[] pKoeff;\n" + "}"); + TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", "", errout.str()); } void testassign1() { // Ticket #1819