Merge pull request #5164 from chrchr-github/chr_Fix11768

Fix #11768 FP autovarInvalidDeallocation
This commit is contained in:
chrchr-github 2023-06-16 22:40:27 +02:00 committed by GitHub
commit 75e0bdfdd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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() {