From 1914d5e630b73d6863c228c4fd378ebe5e5c3d8e Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Fri, 25 May 2018 08:35:37 +0200 Subject: [PATCH] Running astlye --- lib/checkleakautovar.cpp | 53 +++++++++++++++++++--------------------- lib/checkleakautovar.h | 10 ++++---- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 31d98d5f6..5ee634fea 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -206,15 +206,16 @@ static bool isPointerReleased(const Token *startToken, const Token *endToken, un return false; } -/** checks if nameToken is a name of a function in a function call: -* func(arg) -* or -* func(arg) -* @param nameToken Function name token -* @return opening parenthesis token or NULL if not a function call -*/ +/** checks if nameToken is a name of a function in a function call: +* func(arg) +* or +* func(arg) +* @param nameToken Function name token +* @return opening parenthesis token or NULL if not a function call +*/ -static const Token * isFunctionCall(const Token * nameToken) { +static const Token * isFunctionCall(const Token * nameToken) +{ if (nameToken->isName()) { nameToken = nameToken->next(); // check if function is a template @@ -364,7 +365,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, const Token * closingParenthesis = tok->linkAt(1); for (const Token *innerTok = tok->tokAt(2); innerTok && innerTok != closingParenthesis; innerTok = innerTok->next()) { // TODO: replace with checkTokenInsideExpression() - + if (Token::Match(innerTok, "%var% =")) { // allocation? if (Token::Match(innerTok->tokAt(2), "%type% (")) { @@ -639,16 +640,16 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, Token::simpleMatch(deleterToken->link()->linkAt(1), ") {")) { tscopeStart = deleterToken->link()->linkAt(1)->tokAt(1); tscopeEnd = tscopeStart->link(); - // If the deleter is a class, check if class calls the dealloc function + // If the deleter is a class, check if class calls the dealloc function } else if ((dtok = Token::findmatch(deleterToken, "%type%", endDeleterToken)) && dtok->type()) { - const Scope * tscope = dtok->type()->classScope; - if(tscope) { - tscopeStart = tscope->bodyStart; - tscopeEnd = tscope->bodyEnd; - } + const Scope * tscope = dtok->type()->classScope; + if (tscope) { + tscopeStart = tscope->bodyStart; + tscopeEnd = tscope->bodyEnd; + } } - if(tscopeStart && tscopeEnd) { + if (tscopeStart && tscopeEnd) { for (const Token *tok2 = tscopeStart; tok2 != tscopeEnd; tok2 = tok2->next()) { af = _settings->library.dealloc(tok2); if (af) @@ -666,7 +667,8 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, } -const Token * CheckLeakAutoVar::checkTokenInsideExpression(const Token * const tok, VarInfo *varInfo){ +const Token * CheckLeakAutoVar::checkTokenInsideExpression(const Token * const tok, VarInfo *varInfo) +{ std::map &alloctype = varInfo->alloctype; // Deallocation and then dereferencing pointer.. @@ -676,15 +678,12 @@ const Token * CheckLeakAutoVar::checkTokenInsideExpression(const Token * const t bool unknown = false; if (var->second.status == VarInfo::DEALLOC && CheckNullPointer::isPointerDeRef(tok, unknown) && !unknown) { deallocUseError(tok, tok->str()); - } - else if (Token::simpleMatch(tok->tokAt(-2), "= &")) { + } else if (Token::simpleMatch(tok->tokAt(-2), "= &")) { + varInfo->erase(tok->varId()); + } else if (tok->strAt(-1) == "=") { varInfo->erase(tok->varId()); } - else if (tok->strAt(-1) == "=") { - varInfo->erase(tok->varId()); - } - } - else if (Token::Match(tok->previous(), "& %name% = %var% ;")) { + } else if (Token::Match(tok->previous(), "& %name% = %var% ;")) { varInfo->referenced.insert(tok->tokAt(2)->varId()); } } @@ -782,8 +781,7 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin if (Token::Match(arg, "unique_ptr < %type% ,")) { deleterToken = arg->tokAt(4); endDeleterToken = typeEndTok; - } - else if (Token::Match(typeEndTok, "> {|( %var% ,")) { + } else if (Token::Match(typeEndTok, "> {|( %var% ,")) { deleterToken = typeEndTok->tokAt(4); endDeleterToken = typeEndTok->linkAt(1); } @@ -792,8 +790,7 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin const Token * dtok = Token::findmatch(deleterToken, "& %name%", endDeleterToken); if (dtok) { sp_af = _settings->library.dealloc(dtok->tokAt(1)); - } - else { + } else { // If the deleter is a class, check if class calls the dealloc function dtok = Token::findmatch(deleterToken, "%type%", endDeleterToken); if (dtok && dtok->type()) { diff --git a/lib/checkleakautovar.h b/lib/checkleakautovar.h index ecd5fd4d2..72a36a4a5 100644 --- a/lib/checkleakautovar.h +++ b/lib/checkleakautovar.h @@ -119,11 +119,11 @@ private: VarInfo *varInfo, std::set notzero); - /** Check token inside expression. - * @param tok token inside expression. - * @param varInfo Variable info - * @return next token to process (if no other checks needed for this token). NULL if other checks could be performed. - */ + /** Check token inside expression. + * @param tok token inside expression. + * @param varInfo Variable info + * @return next token to process (if no other checks needed for this token). NULL if other checks could be performed. + */ const Token * checkTokenInsideExpression(const Token * const tok, VarInfo *varInfo); /** parse function call */