From 29a49d0641e301aea855306931408fc1daba62fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 14 Sep 2014 11:35:04 +0200 Subject: [PATCH] removed some redundant null pointer checks before calling Token::Match --- lib/symboldatabase.cpp | 4 ++-- lib/templatesimplifier.cpp | 4 ++-- lib/tokenize.cpp | 2 +- lib/tokenlist.cpp | 2 +- lib/valueflow.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index a6197fcdf..321213b1d 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -2608,7 +2608,7 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess) if (tok && isVariableDeclaration(tok, vartok, typetok)) { // If the vartok was set in the if-blocks above, create a entry for this variable.. tok = vartok->next(); - while (tok && Token::Match(tok, "[|{")) + while (Token::Match(tok, "[|{")) tok = tok->link()->next(); if (vartok->varId() == 0) { @@ -2681,7 +2681,7 @@ static const Token* skipPointers(const Token* tok) bool Scope::isVariableDeclaration(const Token* tok, const Token*& vartok, const Token*& typetok) const { - if (tok && check && check->_tokenizer->isCPP() && Token::Match(tok, "throw|new")) + if (check && check->_tokenizer->isCPP() && Token::Match(tok, "throw|new")) return false; const Token* localTypeTok = skipScopeIdentifiers(tok); diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 69dc758c5..72f3cc705 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -285,9 +285,9 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok) return 0; // Function pointer or prototype.. - while (tok && Token::Match(tok, "(|[")) { + while (Token::Match(tok, "(|[")) { tok = tok->link()->next(); - while (tok && Token::Match(tok, "const|volatile")) // Ticket #5786: Skip function cv-qualifiers + while (Token::Match(tok, "const|volatile")) // Ticket #5786: Skip function cv-qualifiers tok = tok->next(); } if (!tok) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 09bf3e20f..226b9e8aa 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1524,7 +1524,7 @@ void Tokenizer::simplifyMulAndParens() } if (!tokend || !(tokend->isAssignmentOp())) continue; - while (tokbegin && (Token::Match(tokbegin, "&|("))) { + while (Token::Match(tokbegin, "&|(")) { if (tokbegin->str() == "&") { if (Token::Match(tokbegin->tokAt(-2), "[;{}&(] *")) { //remove '* &' diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 44bad75f4..19ade2b4c 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -511,7 +511,7 @@ static void compileTerm(Token *&tok, AST_state& state) return; if (Token::Match(tok, "L %str%|%char%")) tok = tok->next(); - if (state.inArrayAssignment && tok->str() == "." && Token::Match(tok->tokAt(-1), ",|{")) // Jump over . in C style struct initialization + if (state.inArrayAssignment && tok->str() == "." && Token::Match(tok->previous(), ",|{")) // Jump over . in C style struct initialization tok = tok->next(); if (tok->isLiteral()) { diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 33a9f0626..e8573eab9 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -260,7 +260,7 @@ static bool isVariableChanged(const Token *start, const Token *end, const unsign return true; const Token *parent = tok->astParent(); - while (parent && Token::Match(parent, ".|::")) + while (Token::Match(parent, ".|::")) parent = parent->astParent(); if (parent && parent->type() == Token::eIncDecOp) return true;