Fix #11768 FP autovarInvalidDeallocation
This commit is contained in:
parent
c033c62190
commit
b41f9af2c5
|
@ -294,6 +294,8 @@ void CheckAutoVariables::autoVariables()
|
||||||
else if ((Token::Match(tok, "%name% ( %var%|%str% ) ;") && mSettings->library.getDeallocFuncInfo(tok)) ||
|
else if ((Token::Match(tok, "%name% ( %var%|%str% ) ;") && mSettings->library.getDeallocFuncInfo(tok)) ||
|
||||||
(mTokenizer->isCPP() && Token::Match(tok, "delete [| ]| (| %var%|%str% !!["))) {
|
(mTokenizer->isCPP() && Token::Match(tok, "delete [| ]| (| %var%|%str% !!["))) {
|
||||||
tok = Token::findmatch(tok->next(), "%var%|%str%");
|
tok = Token::findmatch(tok->next(), "%var%|%str%");
|
||||||
|
if (Token::simpleMatch(tok->astParent(), "."))
|
||||||
|
continue;
|
||||||
if (isArrayVar(tok) || tok->tokType() == Token::eString)
|
if (isArrayVar(tok) || tok->tokType() == Token::eString)
|
||||||
errorInvalidDeallocation(tok, nullptr);
|
errorInvalidDeallocation(tok, nullptr);
|
||||||
else if (tok->variable() && tok->variable()->isPointer()) {
|
else if (tok->variable() && tok->variable()->isPointer()) {
|
||||||
|
|
|
@ -837,6 +837,16 @@ private:
|
||||||
" free(p);\n"
|
" free(p);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("struct E { int* i; };\n" // #11768
|
||||||
|
"struct C { E e; };\n"
|
||||||
|
"int foo(C* cin) {\n"
|
||||||
|
" E* e = &cin->e;\n"
|
||||||
|
" e->i = new int[42];\n"
|
||||||
|
" delete[] e->i;\n"
|
||||||
|
" return 0;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testinvaliddealloc_input() {
|
void testinvaliddealloc_input() {
|
||||||
|
|
Loading…
Reference in New Issue