From b41f9af2c5c2c5b723385a6dd24fe63a328f9ab7 Mon Sep 17 00:00:00 2001 From: chrchr Date: Fri, 16 Jun 2023 17:21:37 +0200 Subject: [PATCH] Fix #11768 FP autovarInvalidDeallocation --- lib/checkautovariables.cpp | 2 ++ test/testautovariables.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) 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() {