#5793 - False positive: Deallocation of an auto-variable (at reference notation)

This commit is contained in:
Alexander Mai 2014-05-12 19:53:49 +02:00
parent a3bb8bf39c
commit 146bf11aa7
2 changed files with 24 additions and 1 deletions

View File

@ -202,7 +202,7 @@ void CheckAutoVariables::autoVariables()
errorInvalidDeallocation(tok);
} else if (Token::Match(tok, "free ( & %var% ) ;") || (_tokenizer->isCPP() && Token::Match(tok, "delete [| ]| (| & %var% !!["))) {
tok = Token::findmatch(tok->next(), "%var%");
if (tok && tok->variable() && tok->variable()->isLocal())
if (isAutoVar(tok))
errorInvalidDeallocation(tok);
}
}

View File

@ -515,6 +515,29 @@ private:
"}");
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", "", errout.str());
check("int main() {\n"
" long *pKoeff[256];\n"
" free (pKoeff);\n"
"}");
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", "", errout.str());
check("void foo() {\n"
" int& intref = Getter();\n"
" delete *intref;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo() {\n"
" FOO& fooref = Getter();\n"
" delete *fooref;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void test() {\n"
" MyObj& obj = *new MyObj;\n"
" delete &obj;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void testinvaliddealloc_C() {