#5793 - False positive: Deallocation of an auto-variable (at reference notation)
This commit is contained in:
parent
a3bb8bf39c
commit
146bf11aa7
|
@ -202,7 +202,7 @@ void CheckAutoVariables::autoVariables()
|
||||||
errorInvalidDeallocation(tok);
|
errorInvalidDeallocation(tok);
|
||||||
} else if (Token::Match(tok, "free ( & %var% ) ;") || (_tokenizer->isCPP() && Token::Match(tok, "delete [| ]| (| & %var% !!["))) {
|
} else if (Token::Match(tok, "free ( & %var% ) ;") || (_tokenizer->isCPP() && Token::Match(tok, "delete [| ]| (| & %var% !!["))) {
|
||||||
tok = Token::findmatch(tok->next(), "%var%");
|
tok = Token::findmatch(tok->next(), "%var%");
|
||||||
if (tok && tok->variable() && tok->variable()->isLocal())
|
if (isAutoVar(tok))
|
||||||
errorInvalidDeallocation(tok);
|
errorInvalidDeallocation(tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -515,6 +515,29 @@ private:
|
||||||
"}");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", "", errout.str());
|
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() {
|
void testinvaliddealloc_C() {
|
||||||
|
|
Loading…
Reference in New Issue