Fixed false positive #5732: autovarInvalidDeallocation on pointer to array

This commit is contained in:
PKEuS 2014-04-27 10:56:55 +02:00
parent bde6698bcd
commit ea23a0467b
2 changed files with 13 additions and 1 deletions

View File

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

View File

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