Merge pull request #5164 from chrchr-github/chr_Fix11768
Fix #11768 FP autovarInvalidDeallocation
This commit is contained in:
commit
75e0bdfdd9
|
@ -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()) {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue