Fix #11768 FP autovarInvalidDeallocation

This commit is contained in:
chrchr 2023-06-16 17:21:37 +02:00
parent c033c62190
commit b41f9af2c5
2 changed files with 12 additions and 0 deletions

View File

@ -294,6 +294,8 @@ void CheckAutoVariables::autoVariables()
else if ((Token::Match(tok, "%name% ( %var%|%str% ) ;") && mSettings->library.getDeallocFuncInfo(tok)) ||
(mTokenizer->isCPP() && Token::Match(tok, "delete [| ]| (| %var%|%str% !!["))) {
tok = Token::findmatch(tok->next(), "%var%|%str%");
if (Token::simpleMatch(tok->astParent(), "."))
continue;
if (isArrayVar(tok) || tok->tokType() == Token::eString)
errorInvalidDeallocation(tok, nullptr);
else if (tok->variable() && tok->variable()->isPointer()) {

View File

@ -837,6 +837,16 @@ private:
" free(p);\n"
"}\n");
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() {