diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 549053ca0..9996a7a8a 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -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()) { diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 5f2631d13..c4f8aa108 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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() {