diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 65180150852..6a99cb2e6b5 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -771,7 +771,7 @@ std::vector getParentValueTypes(const Token* tok, const Settings* set if (Token::simpleMatch(tok->astParent(), "(") && ftok && !tok->astParent()->isCast() && ftok->tokType() != Token::eType) return {}; - if (Token::Match(tok->astParent(), "return|(|{|%assign%") && parent) { + if (parent && Token::Match(tok->astParent(), "return|(|{|%assign%")) { *parent = tok->astParent(); } if (tok->astParent()->valueType()) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 2961873de26..a76a34cc8f2 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1739,7 +1739,7 @@ void CheckClass::operatorEqToSelf() // find the parameter name const Token *rhs = func.argumentList.cbegin()->nameToken(); const Token* out_ifStatementScopeStart = nullptr; - if (!hasAssignSelf(&func, rhs, &out_ifStatementScopeStart)) { + if (!hasAssignSelf(&func, rhs, out_ifStatementScopeStart)) { if (hasAllocation(&func, scope)) operatorEqToSelfError(func.token); } else if (out_ifStatementScopeStart != nullptr) { @@ -1858,7 +1858,7 @@ const Token * CheckClass::getIfStmtBodyStart(const Token *tok, const Token *rhs) return nullptr; } -bool CheckClass::hasAssignSelf(const Function *func, const Token *rhs, const Token **out_ifStatementScopeStart) +bool CheckClass::hasAssignSelf(const Function *func, const Token *rhs, const Token *&out_ifStatementScopeStart) { if (!rhs) return false; @@ -1881,7 +1881,7 @@ bool CheckClass::hasAssignSelf(const Function *func, const Token *rhs, const Tok if (tok2 && tok2->isUnaryOp("&") && tok2->astOperand1()->str() == rhs->str()) ret = true; if (ret) { - *out_ifStatementScopeStart = getIfStmtBodyStart(tok2, rhs); + out_ifStatementScopeStart = getIfStmtBodyStart(tok2, rhs); } return ret ? ChildrenToVisit::done : ChildrenToVisit::op1_and_op2; }); @@ -3399,13 +3399,13 @@ void CheckClass::checkThisUseAfterFree() const Token * freeToken = nullptr; std::set callstack; - checkThisUseAfterFreeRecursive(classScope, &func, &var, std::move(callstack), &freeToken); + checkThisUseAfterFreeRecursive(classScope, &func, &var, std::move(callstack), freeToken); } } } } -bool CheckClass::checkThisUseAfterFreeRecursive(const Scope *classScope, const Function *func, const Variable *selfPointer, std::set callstack, const Token **freeToken) +bool CheckClass::checkThisUseAfterFreeRecursive(const Scope *classScope, const Function *func, const Variable *selfPointer, std::set callstack, const Token *&freeToken) { if (!func || !func->functionScope) return false; @@ -3418,23 +3418,23 @@ bool CheckClass::checkThisUseAfterFreeRecursive(const Scope *classScope, const F const Token * const bodyStart = func->functionScope->bodyStart; const Token * const bodyEnd = func->functionScope->bodyEnd; for (const Token *tok = bodyStart; tok != bodyEnd; tok = tok->next()) { - const bool isDestroyed = *freeToken != nullptr && !func->isStatic(); + const bool isDestroyed = freeToken != nullptr && !func->isStatic(); if (Token::Match(tok, "delete %var% ;") && selfPointer == tok->next()->variable()) { - *freeToken = tok; + freeToken = tok; tok = tok->tokAt(2); } else if (Token::Match(tok, "%var% . reset ( )") && selfPointer == tok->variable()) - *freeToken = tok; + freeToken = tok; else if (Token::Match(tok->previous(), "!!. %name% (") && tok->function() && tok->function()->nestedIn == classScope) { if (isDestroyed) { - thisUseAfterFree(selfPointer->nameToken(), *freeToken, tok); + thisUseAfterFree(selfPointer->nameToken(), freeToken, tok); return true; } if (checkThisUseAfterFreeRecursive(classScope, tok->function(), selfPointer, callstack, freeToken)) return true; } else if (isDestroyed && Token::Match(tok->previous(), "!!. %name%") && tok->variable() && tok->variable()->scope() == classScope && !tok->variable()->isStatic() && !tok->variable()->isArgument()) { - thisUseAfterFree(selfPointer->nameToken(), *freeToken, tok); + thisUseAfterFree(selfPointer->nameToken(), freeToken, tok); return true; - } else if (*freeToken && Token::Match(tok, "return|throw")) { + } else if (freeToken && Token::Match(tok, "return|throw")) { // TODO return tok->str() == "throw"; } else if (tok->str() == "{" && tok->scope()->type == Scope::ScopeType::eLambda) { diff --git a/lib/checkclass.h b/lib/checkclass.h index bc2a9d5116d..ac81b698a54 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -298,7 +298,7 @@ class CPPCHECKLIB CheckClass : public Check { bool hasAllocation(const Function *func, const Scope* scope) const; bool hasAllocation(const Function *func, const Scope* scope, const Token *start, const Token *end) const; bool hasAllocationInIfScope(const Function *func, const Scope* scope, const Token *ifStatementScopeStart) const; - static bool hasAssignSelf(const Function *func, const Token *rhs, const Token **out_ifStatementScopeStart); + static bool hasAssignSelf(const Function *func, const Token *rhs, const Token *&out_ifStatementScopeStart); enum class Bool { TRUE, FALSE, BAILOUT }; static Bool isInverted(const Token *tok, const Token *rhs); static const Token * getIfStmtBodyStart(const Token *tok, const Token *rhs); @@ -411,7 +411,7 @@ class CPPCHECKLIB CheckClass : public Check { /** * @brief Helper for checkThisUseAfterFree */ - bool checkThisUseAfterFreeRecursive(const Scope *classScope, const Function *func, const Variable *selfPointer, std::set callstack, const Token **freeToken); + bool checkThisUseAfterFreeRecursive(const Scope *classScope, const Function *func, const Variable *selfPointer, std::set callstack, const Token *&freeToken); }; /// @} //--------------------------------------------------------------------------- diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index f5e250a0cd8..3203bef3986 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -1573,8 +1573,8 @@ void CheckCondition::alwaysTrueFalse() { const ValueFlow::Value *zeroValue = nullptr; const Token *nonZeroExpr = nullptr; - if (CheckOther::comparisonNonZeroExpressionLessThanZero(tok, &zeroValue, &nonZeroExpr, /*suppress*/ true) || - CheckOther::testIfNonZeroExpressionIsPositive(tok, &zeroValue, &nonZeroExpr)) + if (CheckOther::comparisonNonZeroExpressionLessThanZero(tok, zeroValue, nonZeroExpr, /*suppress*/ true) || + CheckOther::testIfNonZeroExpressionIsPositive(tok, zeroValue, nonZeroExpr)) continue; } diff --git a/lib/checkio.cpp b/lib/checkio.cpp index b4fc0a4abb6..cd919537b75 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -487,7 +487,7 @@ void CheckIO::invalidScanfError(const Token *tok) //--------------------------------------------------------------------------- static bool findFormat(nonneg int arg, const Token *firstArg, - const Token **formatStringTok, const Token **formatArgTok) + const Token *&formatStringTok, const Token *&formatArgTok) { const Token* argTok = firstArg; @@ -495,8 +495,8 @@ static bool findFormat(nonneg int arg, const Token *firstArg, argTok = argTok->nextArgument(); if (Token::Match(argTok, "%str% [,)]")) { - *formatArgTok = argTok->nextArgument(); - *formatStringTok = argTok; + formatArgTok = argTok->nextArgument(); + formatStringTok = argTok; return true; } if (Token::Match(argTok, "%var% [,)]") && @@ -506,13 +506,13 @@ static bool findFormat(nonneg int arg, const Token *firstArg, (argTok->variable()->dimensions().size() == 1 && argTok->variable()->dimensionKnown(0) && argTok->variable()->dimension(0) != 0))) { - *formatArgTok = argTok->nextArgument(); + formatArgTok = argTok->nextArgument(); if (!argTok->values().empty()) { const std::list::const_iterator value = std::find_if( argTok->values().cbegin(), argTok->values().cend(), std::mem_fn(&ValueFlow::Value::isTokValue)); if (value != argTok->values().cend() && value->isTokValue() && value->tokvalue && value->tokvalue->tokType() == Token::eString) { - *formatStringTok = value->tokvalue; + formatStringTok = value->tokvalue; } } return true; @@ -552,37 +552,37 @@ void CheckIO::checkWrongPrintfScanfArguments() if (formatStringArgNo >= 0) { // formatstring found in library. Find format string and first argument belonging to format string. - if (!findFormat(formatStringArgNo, tok->tokAt(2), &formatStringTok, &argListTok)) + if (!findFormat(formatStringArgNo, tok->tokAt(2), formatStringTok, argListTok)) continue; } else if (Token::simpleMatch(tok, "swprintf (")) { if (Token::Match(tok->tokAt(2)->nextArgument(), "%str%")) { // Find third parameter and format string - if (!findFormat(1, tok->tokAt(2), &formatStringTok, &argListTok)) + if (!findFormat(1, tok->tokAt(2), formatStringTok, argListTok)) continue; } else { // Find fourth parameter and format string - if (!findFormat(2, tok->tokAt(2), &formatStringTok, &argListTok)) + if (!findFormat(2, tok->tokAt(2), formatStringTok, argListTok)) continue; } } else if (isWindows && Token::Match(tok, "sprintf_s|swprintf_s (")) { // template int sprintf_s(char (&buffer)[size], const char *format, ...); - if (findFormat(1, tok->tokAt(2), &formatStringTok, &argListTok)) { + if (findFormat(1, tok->tokAt(2), formatStringTok, argListTok)) { if (!formatStringTok) continue; } // int sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...); - else if (findFormat(2, tok->tokAt(2), &formatStringTok, &argListTok)) { + else if (findFormat(2, tok->tokAt(2), formatStringTok, argListTok)) { if (!formatStringTok) continue; } } else if (isWindows && Token::Match(tok, "_snprintf_s|_snwprintf_s (")) { // template int _snprintf_s(char (&buffer)[size], size_t count, const char *format, ...); - if (findFormat(2, tok->tokAt(2), &formatStringTok, &argListTok)) { + if (findFormat(2, tok->tokAt(2), formatStringTok, argListTok)) { if (!formatStringTok) continue; } // int _snprintf_s(char *buffer, size_t sizeOfBuffer, size_t count, const char *format, ...); - else if (findFormat(3, tok->tokAt(2), &formatStringTok, &argListTok)) { + else if (findFormat(3, tok->tokAt(2), formatStringTok, argListTok)) { if (!formatStringTok) continue; } diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 145693b504c..031ce9cef08 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2714,13 +2714,13 @@ void CheckOther::checkSignOfUnsignedVariable() for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { const ValueFlow::Value *zeroValue = nullptr; const Token *nonZeroExpr = nullptr; - if (comparisonNonZeroExpressionLessThanZero(tok, &zeroValue, &nonZeroExpr)) { + if (comparisonNonZeroExpressionLessThanZero(tok, zeroValue, nonZeroExpr)) { const ValueType* vt = nonZeroExpr->valueType(); if (vt->pointer) pointerLessThanZeroError(tok, zeroValue); else unsignedLessThanZeroError(tok, zeroValue, nonZeroExpr->expressionString()); - } else if (testIfNonZeroExpressionIsPositive(tok, &zeroValue, &nonZeroExpr)) { + } else if (testIfNonZeroExpressionIsPositive(tok, zeroValue, nonZeroExpr)) { const ValueType* vt = nonZeroExpr->valueType(); if (vt->pointer) pointerPositiveError(tok, zeroValue); @@ -2731,7 +2731,7 @@ void CheckOther::checkSignOfUnsignedVariable() } } -bool CheckOther::comparisonNonZeroExpressionLessThanZero(const Token *tok, const ValueFlow::Value **zeroValue, const Token **nonZeroExpr, bool suppress) +bool CheckOther::comparisonNonZeroExpressionLessThanZero(const Token *tok, const ValueFlow::Value *&zeroValue, const Token *&nonZeroExpr, bool suppress) { if (!tok->isComparisonOp() || !tok->astOperand1() || !tok->astOperand2()) return false; @@ -2740,24 +2740,24 @@ bool CheckOther::comparisonNonZeroExpressionLessThanZero(const Token *tok, const const ValueFlow::Value *v2 = tok->astOperand2()->getValue(0); if (Token::Match(tok, "<|<=") && v2 && v2->isKnown()) { - *zeroValue = v2; - *nonZeroExpr = tok->astOperand1(); + zeroValue = v2; + nonZeroExpr = tok->astOperand1(); } else if (Token::Match(tok, ">|>=") && v1 && v1->isKnown()) { - *zeroValue = v1; - *nonZeroExpr = tok->astOperand2(); + zeroValue = v1; + nonZeroExpr = tok->astOperand2(); } else { return false; } - if (const Variable* var = (*nonZeroExpr)->variable()) + if (const Variable* var = nonZeroExpr->variable()) if (var->typeStartToken()->isTemplateArg()) return suppress; - const ValueType* vt = (*nonZeroExpr)->valueType(); + const ValueType* vt = nonZeroExpr->valueType(); return vt && (vt->pointer || vt->sign == ValueType::UNSIGNED); } -bool CheckOther::testIfNonZeroExpressionIsPositive(const Token *tok, const ValueFlow::Value **zeroValue, const Token **nonZeroExpr) +bool CheckOther::testIfNonZeroExpressionIsPositive(const Token *tok, const ValueFlow::Value *&zeroValue, const Token *&nonZeroExpr) { if (!tok->isComparisonOp() || !tok->astOperand1() || !tok->astOperand2()) return false; @@ -2766,16 +2766,16 @@ bool CheckOther::testIfNonZeroExpressionIsPositive(const Token *tok, const Value const ValueFlow::Value *v2 = tok->astOperand2()->getValue(0); if (Token::simpleMatch(tok, ">=") && v2 && v2->isKnown()) { - *zeroValue = v2; - *nonZeroExpr = tok->astOperand1(); + zeroValue = v2; + nonZeroExpr = tok->astOperand1(); } else if (Token::simpleMatch(tok, "<=") && v1 && v1->isKnown()) { - *zeroValue = v1; - *nonZeroExpr = tok->astOperand2(); + zeroValue = v1; + nonZeroExpr = tok->astOperand2(); } else { return false; } - const ValueType* vt = (*nonZeroExpr)->valueType(); + const ValueType* vt = nonZeroExpr->valueType(); return vt && (vt->pointer || vt->sign == ValueType::UNSIGNED); } @@ -3864,7 +3864,7 @@ void CheckOther::checkModuloOfOneError(const Token *tok) //----------------------------------------------------------------------------- // Overlapping write (undefined behavior) //----------------------------------------------------------------------------- -static bool getBufAndOffset(const Token *expr, const Token **buf, MathLib::bigint *offset) +static bool getBufAndOffset(const Token *expr, const Token *&buf, MathLib::bigint *offset) { if (!expr) return false; @@ -3885,7 +3885,7 @@ static bool getBufAndOffset(const Token *expr, const Token **buf, MathLib::bigin return false; } } else if (expr->valueType() && expr->valueType()->pointer > 0) { - *buf = expr; + buf = expr; *offset = 0; return true; } else { @@ -3895,7 +3895,7 @@ static bool getBufAndOffset(const Token *expr, const Token **buf, MathLib::bigin return false; if (!offsetToken->hasKnownIntValue()) return false; - *buf = bufToken; + buf = bufToken; *offset = offsetToken->getKnownIntValue(); return true; } @@ -3974,9 +3974,9 @@ void CheckOther::checkOverlappingWrite() const MathLib::bigint sizeValue = args[nonOverlappingData->sizeArg-1]->getKnownIntValue(); const Token *buf1, *buf2; MathLib::bigint offset1, offset2; - if (!getBufAndOffset(ptr1, &buf1, &offset1)) + if (!getBufAndOffset(ptr1, buf1, &offset1)) continue; - if (!getBufAndOffset(ptr2, &buf2, &offset2)) + if (!getBufAndOffset(ptr2, buf2, &offset2)) continue; if (offset1 < offset2 && offset1 + sizeValue <= offset2) diff --git a/lib/checkother.h b/lib/checkother.h index 1b7d080e7e5..b64281d46de 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -56,10 +56,10 @@ class CPPCHECKLIB CheckOther : public Check { CheckOther() : Check(myName()) {} /** Is expression a comparison that checks if a nonzero (unsigned/pointer) expression is less than zero? */ - static bool comparisonNonZeroExpressionLessThanZero(const Token *tok, const ValueFlow::Value **zeroValue, const Token **nonZeroExpr, bool suppress = false); + static bool comparisonNonZeroExpressionLessThanZero(const Token *tok, const ValueFlow::Value *&zeroValue, const Token *&nonZeroExpr, bool suppress = false); /** Is expression a comparison that checks if a nonzero (unsigned/pointer) expression is positive? */ - static bool testIfNonZeroExpressionIsPositive(const Token *tok, const ValueFlow::Value **zeroValue, const Token **nonZeroExpr); + static bool testIfNonZeroExpressionIsPositive(const Token *tok, const ValueFlow::Value *&zeroValue, const Token *&nonZeroExpr); private: /** @brief This constructor is used when running checks. */ diff --git a/lib/ctu.cpp b/lib/ctu.cpp index 19a0e834136..789d0c675c8 100644 --- a/lib/ctu.cpp +++ b/lib/ctu.cpp @@ -276,7 +276,7 @@ std::list CTU::loadUnsafeUsageListFromXml(const tiny return ret; } -static int isCallFunction(const Scope *scope, int argnr, const Token **tok) +static int isCallFunction(const Scope *scope, int argnr, const Token *&tok) { const Variable * const argvar = scope->function->getArgumentVar(argnr); if (!argvar->isPointer()) @@ -299,7 +299,7 @@ static int isCallFunction(const Scope *scope, int argnr, const Token **tok) break; if (!prev->astOperand1() || !prev->astOperand1()->function()) break; - *tok = prev->previous(); + tok = prev->previous(); return argnr2; } return -1; @@ -424,7 +424,7 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer *tokenizer) // Nested function calls for (int argnr = 0; argnr < scopeFunction->argCount(); ++argnr) { const Token *tok; - const int argnr2 = isCallFunction(&scope, argnr, &tok); + const int argnr2 = isCallFunction(&scope, argnr, tok); if (argnr2 > 0) { FileInfo::NestedCall nestedCall(tokenizer, scopeFunction, tok); nestedCall.myArgNr = argnr + 1; diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 532da5ed879..62a1c2b2a2b 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -97,11 +97,11 @@ void ProgramMemory::setIntValue(const Token* expr, MathLib::bigint value, bool i setValue(expr, v); } -bool ProgramMemory::getTokValue(nonneg int exprid, const Token** result) const +bool ProgramMemory::getTokValue(nonneg int exprid, const Token*& result) const { const ValueFlow::Value* value = getValue(exprid); if (value && value->isTokValue()) { - *result = value->tokvalue; + result = value->tokvalue; return true; } return false; @@ -1469,7 +1469,7 @@ namespace { return lhs; } else if (expr->str() == "[" && expr->astOperand1() && expr->astOperand2()) { const Token* tokvalue = nullptr; - if (!pm->getTokValue(expr->astOperand1()->exprId(), &tokvalue)) { + if (!pm->getTokValue(expr->astOperand1()->exprId(), tokvalue)) { auto tokvalue_it = std::find_if(expr->astOperand1()->values().cbegin(), expr->astOperand1()->values().cend(), std::mem_fn(&ValueFlow::Value::isTokValue)); diff --git a/lib/programmemory.h b/lib/programmemory.h index 717284efb24..b746e2e8dd7 100644 --- a/lib/programmemory.h +++ b/lib/programmemory.h @@ -115,7 +115,7 @@ struct ProgramMemory { void setUnknown(const Token* expr); - bool getTokValue(nonneg int exprid, const Token** result) const; + bool getTokValue(nonneg int exprid, const Token*& result) const; bool hasValue(nonneg int exprid); const ValueFlow::Value& at(nonneg int exprid) const; diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 4f86497551c..4a883977ee2 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -542,7 +542,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } // class function? - else if (isFunction(tok, scope, &funcStart, &argStart, &declEnd)) { + else if (isFunction(tok, scope, funcStart, argStart, declEnd)) { if (tok->previous()->str() != "::" || tok->strAt(-2) == scope->className) { Function function(tok, scope, funcStart, argStart); @@ -591,7 +591,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() Function* funcptr = &scope->functionList.back(); const Token *tok2 = funcStart; - addNewFunction(&scope, &tok2); + addNewFunction(scope, tok2); if (scope) { scope->functionOf = function.nestedIn; scope->function = funcptr; @@ -608,7 +608,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() const Scope * const nested = scope->findInNestedListRecursive(tok->strAt(-2)); if (nested) - addClassFunction(&scope, &tok, argStart); + addClassFunction(scope, tok, argStart); else { /** @todo handle friend functions */ } @@ -645,20 +645,20 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() const Token *declEnd = nullptr; // function? - if (isFunction(tok, scope, &funcStart, &argStart, &declEnd)) { + if (isFunction(tok, scope, funcStart, argStart, declEnd)) { // has body? if (declEnd && declEnd->str() == "{") { tok = funcStart; // class function if (tok->previous() && tok->previous()->str() == "::") - addClassFunction(&scope, &tok, argStart); + addClassFunction(scope, tok, argStart); // class destructor else if (tok->previous() && tok->previous()->str() == "~" && tok->strAt(-2) == "::") - addClassFunction(&scope, &tok, argStart); + addClassFunction(scope, tok, argStart); // regular function else { @@ -676,7 +676,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() else if (declEnd && declEnd->str() == ";") { if (tok->astParent() && tok->astParent()->str() == "::" && Token::Match(declEnd->previous(), "default|delete")) { - addClassFunction(&scope, &tok, argStart); + addClassFunction(scope, tok, argStart); continue; } @@ -761,7 +761,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() const Token *funcStart = nullptr; const Token *argStart = nullptr; const Token *declEnd = nullptr; - if (isFunction(ftok, scope, &funcStart, &argStart, &declEnd)) { + if (isFunction(ftok, scope, funcStart, argStart, declEnd)) { if (declEnd && declEnd->str() == ";") { bool newFunc = true; // Is this function already in the database? auto range = scope->functionMap.equal_range(ftok->str()); @@ -1886,7 +1886,7 @@ SymbolDatabase::~SymbolDatabase() } } -bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const Token **funcStart, const Token **argStart, const Token** declEnd) const +bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const Token *&funcStart, const Token *&argStart, const Token*& declEnd) const { if (tok->varId()) return false; @@ -1903,9 +1903,9 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const argStartTok = tok->link()->linkAt(-2); else argStartTok = tok->link()->linkAt(-1); - *funcStart = argStartTok->previous(); - *argStart = argStartTok; - *declEnd = Token::findmatch(tok2->link()->next(), "{|;"); + funcStart = argStartTok->previous(); + argStart = argStartTok; + declEnd = Token::findmatch(tok2->link()->next(), "{|;"); return true; } if (tok2 && tok2->str() == "[") { @@ -1917,9 +1917,9 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const argStartTok = tok->link()->linkAt(-2); else argStartTok = tok->link()->linkAt(-1); - *funcStart = argStartTok->previous(); - *argStart = argStartTok; - *declEnd = Token::findmatch(tok2, "{|;"); + funcStart = argStartTok->previous(); + argStart = argStartTok; + declEnd = Token::findmatch(tok2, "{|;"); return true; } } @@ -2031,9 +2031,9 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const Token::Match(tok2, ": ::| %name% (|::|<|{") || Token::Match(tok2, "&|&&| ;|{") || Token::Match(tok2, "= delete|default ;"))) { - *funcStart = tok; - *argStart = tok->next(); - *declEnd = Token::findmatch(tok2, "{|;"); + funcStart = tok; + argStart = tok->next(); + declEnd = Token::findmatch(tok2, "{|;"); return true; } } @@ -2044,9 +2044,9 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const tok->isUpperCaseName() && Token::simpleMatch(tok->linkAt(1), ") {") && (!tok->previous() || Token::Match(tok->previous(), "[;{}]"))) { - *funcStart = tok; - *argStart = tok->next(); - *declEnd = tok->linkAt(1)->next(); + funcStart = tok; + argStart = tok->next(); + declEnd = tok->linkAt(1)->next(); return true; } @@ -2056,9 +2056,9 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const if (Token::Match(tok2, ") const| ;|{|=") || Token::Match(tok2, ") : ::| %name% (|::|<|{") || Token::Match(tok2, ") const| noexcept {|;|(")) { - *funcStart = tok; - *argStart = tok2->link(); - *declEnd = Token::findmatch(tok2->next(), "{|;"); + funcStart = tok; + argStart = tok2->link(); + declEnd = Token::findmatch(tok2->next(), "{|;"); return true; } } @@ -2069,9 +2069,9 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const (!tok->previous() || Token::Match(tok->previous(), ";|}"))) { if (tok->isC()) { returnImplicitIntError(tok); - *funcStart = tok; - *argStart = tok->next(); - *declEnd = tok->linkAt(1)->next(); + funcStart = tok; + argStart = tok->next(); + declEnd = tok->linkAt(1)->next(); return true; } mTokenizer.syntaxError(tok); @@ -2763,8 +2763,8 @@ static bool typesMatch( const Token *first_token, const Scope *second_scope, const Token *second_token, - const Token **new_first, - const Token **new_second) + const Token *&new_first, + const Token *&new_second) { // get first type const Type* first_type = first_scope->check->findType(first_token, first_scope, /*lookOutside*/ true); @@ -2781,8 +2781,8 @@ static bool typesMatch( tok2 = tok2->next(); // update parser token positions if (tok1 && tok2) { - *new_first = tok1->previous(); - *new_second = tok2->previous(); + new_first = tok1->previous(); + new_second = tok2->previous(); return true; } } @@ -2958,7 +2958,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se first = first->tokAt(offset); // same type with different qualification - else if (typesMatch(scope, first->next(), nestedIn, second->next(), &first, &second)) + else if (typesMatch(scope, first->next(), nestedIn, second->next(), first, second)) ; // variable with class path @@ -3225,7 +3225,7 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co function->token = funcStart; function->hasBody(true); - addNewFunction(&scope, &tok); + addNewFunction(scope, tok); if (scope) { scope->function = function; @@ -3242,16 +3242,16 @@ Function* SymbolDatabase::addGlobalFunctionDecl(Scope*& scope, const Token *tok, return &scope->functionList.back(); } -void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const Token *argStart) +void SymbolDatabase::addClassFunction(Scope *&scope, const Token *&tok, const Token *argStart) { - const bool destructor((*tok)->previous()->str() == "~"); + const bool destructor(tok->previous()->str() == "~"); const bool has_const(argStart->link()->strAt(1) == "const"); const bool lval(argStart->link()->strAt(has_const ? 2 : 1) == "&"); const bool rval(argStart->link()->strAt(has_const ? 2 : 1) == "&&"); int count = 0; std::string path; unsigned int path_length = 0; - const Token *tok1 = (*tok); + const Token *tok1 = tok; if (destructor) tok1 = tok1->previous(); @@ -3292,14 +3292,14 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To bool match = false; // check in namespace if using found - if (*scope == scope1 && !scope1->usingList.empty()) { + if (scope == scope1 && !scope1->usingList.empty()) { std::vector::const_iterator it2; for (it2 = scope1->usingList.cbegin(); it2 != scope1->usingList.cend(); ++it2) { if (it2->scope) { Function * func = findFunctionInScope(tok1, it2->scope, path, path_length); if (func) { if (!func->hasBody()) { - const Token *closeParen = (*tok)->next()->link(); + const Token *closeParen = tok->next()->link(); if (closeParen) { const Token *eq = Tokenizer::isFunctionHead(closeParen, ";"); if (eq && Token::simpleMatch(eq->tokAt(-2), "= default ;")) { @@ -3308,13 +3308,13 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To } } func->hasBody(true); - func->token = *tok; + func->token = tok; func->arg = argStart; addNewFunction(scope, tok); - if (*scope) { - (*scope)->functionOf = func->nestedIn; - (*scope)->function = func; - (*scope)->function->functionScope = *scope; + if (scope) { + scope->functionOf = func->nestedIn; + scope->function = func; + scope->function->functionScope = scope; } return; } @@ -3326,14 +3326,14 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To const bool isAnonymousNamespace = (scope1->type == Scope::eNamespace && scope1->className.empty()); if ((scope1->className == tok1->str() && (scope1->type != Scope::eFunction)) || isAnonymousNamespace) { // do the scopes match (same scope) or do their names match (multiple namespaces) - if ((*scope == scope1->nestedIn) || (*scope && - (*scope)->className == scope1->nestedIn->className && - !(*scope)->className.empty() && - (*scope)->type == scope1->nestedIn->type)) { + if ((scope == scope1->nestedIn) || (scope && + scope->className == scope1->nestedIn->className && + !scope->className.empty() && + scope->type == scope1->nestedIn->type)) { // nested scopes => check that they match { - const Scope *s1 = *scope; + const Scope *s1 = scope; const Scope *s2 = scope1->nestedIn; while (s1 && s2) { if (s1->className != s2->className) @@ -3367,12 +3367,12 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To } if (match) { - auto range = scope1->functionMap.equal_range((*tok)->str()); + auto range = scope1->functionMap.equal_range(tok->str()); for (std::multimap::const_iterator it = range.first; it != range.second; ++it) { auto * func = const_cast(it->second); if (!func->hasBody()) { - if (func->argsMatch(scope1, func->argDef, (*tok)->next(), path, path_length)) { - const Token *closeParen = (*tok)->next()->link(); + if (func->argsMatch(scope1, func->argDef, tok->next(), path, path_length)) { + const Token *closeParen = tok->next()->link(); if (closeParen) { const Token *eq = Tokenizer::isFunctionHead(closeParen, ";"); if (eq && Token::simpleMatch(eq->tokAt(-2), "= default ;")) { @@ -3393,13 +3393,13 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To } if (func->hasBody()) { - func->token = *tok; + func->token = tok; func->arg = argStart; addNewFunction(scope, tok); - if (*scope) { - (*scope)->functionOf = scope1; - (*scope)->function = func; - (*scope)->function->functionScope = *scope; + if (scope) { + scope->functionOf = scope1; + scope->function = func; + scope->function->functionScope = scope; } return; } @@ -3413,10 +3413,10 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To addNewFunction(scope, tok); } -void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok) +void SymbolDatabase::addNewFunction(Scope *&scope, const Token *&tok) { - const Token *tok1 = *tok; - scopeList.emplace_back(this, tok1, *scope); + const Token *tok1 = tok; + scopeList.emplace_back(this, tok1, scope); Scope *newScope = &scopeList.back(); // find start of function '{' @@ -3440,15 +3440,15 @@ void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok) if (!newScope->bodyEnd) { mTokenizer.unmatchedToken(tok1); } else { - (*scope)->nestedList.push_back(newScope); - *scope = newScope; + scope->nestedList.push_back(newScope); + scope = newScope; } } else if (tok1 && Token::Match(tok1->tokAt(-2), "= default|delete ;")) { scopeList.pop_back(); } else { - throw InternalError(*tok, "Analysis failed (function not recognized). If the code is valid then please report this failure."); + throw InternalError(tok, "Analysis failed (function not recognized). If the code is valid then please report this failure."); } - *tok = tok1; + tok = tok1; } bool Type::isClassType() const diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 901991313d4..0dfebdbedb6 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -1435,11 +1435,11 @@ class CPPCHECKLIB SymbolDatabase { void debugSymbolDatabase() const; - void addClassFunction(Scope **scope, const Token **tok, const Token *argStart); + void addClassFunction(Scope *&scope, const Token *&tok, const Token *argStart); static Function *addGlobalFunctionDecl(Scope*& scope, const Token* tok, const Token *argStart, const Token* funcStart); Function *addGlobalFunction(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart); - void addNewFunction(Scope **scope, const Token **tok); - bool isFunction(const Token *tok, const Scope* outerScope, const Token **funcStart, const Token **argStart, const Token** declEnd) const; + void addNewFunction(Scope *&scope, const Token *&tok); + bool isFunction(const Token *tok, const Scope* outerScope, const Token *&funcStart, const Token *&argStart, const Token*& declEnd) const; const Type *findTypeInNested(const Token *startTok, const Scope *startScope) const; const Scope *findNamespace(const Token * tok, const Scope * scope) const; static Function *findFunctionInScope(const Token *func, const Scope *ns, const std::string & path, nonneg int path_length); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 005bc6146fa..ccf32d207db 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -85,13 +85,13 @@ static bool isEnumStart(const Token* tok) } template -static void skipEnumBody(T **tok) +static void skipEnumBody(T *&tok) { - T *defStart = *tok; + T *defStart = tok; while (Token::Match(defStart, "%name%|::|:")) defStart = defStart->next(); if (defStart && defStart->str() == "{") - *tok = defStart->link()->next(); + tok = defStart->link()->next(); } const Token * Tokenizer::isFunctionHead(const Token *tok, const std::string &endsWith) @@ -212,10 +212,10 @@ nonneg int Tokenizer::sizeOfType(const Token *type) const //--------------------------------------------------------------------------- // check if this statement is a duplicate definition -bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token *typeDef) const +bool Tokenizer::duplicateTypedef(Token *&tokPtr, const Token *name, const Token *typeDef) const { // check for an end of definition - Token * tok = *tokPtr; + Token * tok = tokPtr; if (tok && Token::Match(tok->next(), ";|,|[|=|)|>|(|{")) { Token * end = tok->next(); @@ -253,7 +253,7 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token if (!Token::Match(tok->tokAt(-3), ",|<")) return false; - *tokPtr = end->link(); + tokPtr = end->link(); return true; } } @@ -264,7 +264,7 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token if (Token::Match(tok->previous(), "%type%") && !Token::Match(tok->previous(), "return|new|const|struct")) { // duplicate definition so skip entire function - *tokPtr = end->next()->link(); + tokPtr = end->next()->link(); return true; } } else if (end->str() == ">") { // template parameter ? @@ -275,7 +275,7 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token while (end && end->str() != "{") end = end->next(); if (end) { - *tokPtr = end->link(); + tokPtr = end->link(); return true; } } @@ -320,7 +320,7 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token tok = tok->previous(); } - if ((*tokPtr)->strAt(1) != "(" || !Token::Match((*tokPtr)->linkAt(1), ") .|(|[")) + if (tokPtr->strAt(1) != "(" || !Token::Match(tokPtr->linkAt(1), ") .|(|[")) return true; } } @@ -1844,7 +1844,7 @@ void Tokenizer::simplifyTypedefCpp() } } else if (Token::Match(tok2->previous(), "case|;|{|} %type% :")) { tok2 = tok2->next(); - } else if (duplicateTypedef(&tok2, typeName, typeDef)) { + } else if (duplicateTypedef(tok2, typeName, typeDef)) { // skip to end of scope if not already there if (tok2->str() != "}") { while (tok2->next()) { @@ -2492,22 +2492,22 @@ namespace { } }; - void setScopeInfo(Token *tok, ScopeInfo3 **scopeInfo, bool debug=false) + void setScopeInfo(Token *tok, ScopeInfo3 *&scopeInfo, bool debug=false) { if (!tok) return; - if (tok->str() == "{" && (*scopeInfo)->parent && tok == (*scopeInfo)->bodyStart) + if (tok->str() == "{" && scopeInfo->parent && tok == scopeInfo->bodyStart) return; if (tok->str() == "}") { - if ((*scopeInfo)->parent && tok == (*scopeInfo)->bodyEnd) - *scopeInfo = (*scopeInfo)->parent; + if (scopeInfo->parent && tok == scopeInfo->bodyEnd) + scopeInfo = scopeInfo->parent; else { // Try to find parent scope - ScopeInfo3 *parent = (*scopeInfo)->parent; + ScopeInfo3 *parent = scopeInfo->parent; while (parent && parent->bodyEnd != tok) parent = parent->parent; if (parent) { - *scopeInfo = parent; + scopeInfo = parent; if (debug) throw std::runtime_error("Internal error: unmatched }"); } @@ -2525,7 +2525,7 @@ namespace { nameSpace += tok1->str(); tok1 = tok1->next(); } - (*scopeInfo)->usingNamespaces.insert(std::move(nameSpace)); + scopeInfo->usingNamespaces.insert(std::move(nameSpace)); } // check for member function else if (tok->str() == "{") { @@ -2562,13 +2562,13 @@ namespace { scope = tok1->strAt(-3) + " :: " + scope; tok1 = tok1->tokAt(-2); } - *scopeInfo = (*scopeInfo)->addChild(ScopeInfo3::MemberFunction, scope, tok, tok->link()); + scopeInfo = scopeInfo->addChild(ScopeInfo3::MemberFunction, scope, tok, tok->link()); added = true; } } if (!added) - *scopeInfo = (*scopeInfo)->addChild(ScopeInfo3::Other, emptyString, tok, tok->link()); + scopeInfo = scopeInfo->addChild(ScopeInfo3::Other, emptyString, tok, tok->link()); } return; } @@ -2583,7 +2583,7 @@ namespace { // add record type to scope info if (record) - (*scopeInfo)->recordTypes.insert(classname); + scopeInfo->recordTypes.insert(classname); tok = tok->next(); // skip template parameters @@ -2623,8 +2623,8 @@ namespace { } if (tok && tok->str() == "{") { - *scopeInfo = (*scopeInfo)->addChild(record ? ScopeInfo3::Record : ScopeInfo3::Namespace, classname, tok, tok->link()); - (*scopeInfo)->baseTypes = std::move(baseTypes); + scopeInfo = scopeInfo->addChild(record ? ScopeInfo3::Record : ScopeInfo3::Namespace, classname, tok, tok->link()); + scopeInfo->baseTypes = std::move(baseTypes); } } @@ -2645,19 +2645,19 @@ namespace { bool usingMatch( const Token *nameToken, const std::string &scope, - Token **tok, + Token *&tok, const std::string &scope1, const ScopeInfo3 *currentScope, const ScopeInfo3 *memberClassScope) { - Token *tok1 = *tok; + Token *tok1 = tok; if (tok1 && tok1->str() != nameToken->str()) return false; // skip this using if (tok1 == nameToken) { - *tok = findSemicolon(tok1); + tok = findSemicolon(tok1); return false; } @@ -2666,7 +2666,7 @@ namespace { // fixme: this is wrong // skip to end of scope if (currentScope->bodyEnd) - *tok = const_cast(currentScope->bodyEnd->previous()); + tok = const_cast(currentScope->bodyEnd->previous()); return false; } @@ -2898,7 +2898,7 @@ bool Tokenizer::simplifyUsing() if (Token::Match(tok, "{|}|namespace|class|struct|union") || Token::Match(tok, "using namespace %name% ;|::")) { try { - setScopeInfo(tok, ¤tScope, mSettings.debugwarnings); + setScopeInfo(tok, currentScope, mSettings.debugwarnings); } catch (const std::runtime_error &) { reportError(tok, Severity::debug, "simplifyUsingUnmatchedBodyEnd", "simplifyUsing: unmatched body end"); @@ -3055,7 +3055,7 @@ bool Tokenizer::simplifyUsing() if ((Token::Match(tok1, "{|}|namespace|class|struct|union") && tok1->strAt(-1) != "using") || Token::Match(tok1, "using namespace %name% ;|::")) { try { - setScopeInfo(tok1, ¤tScope1, mSettings.debugwarnings); + setScopeInfo(tok1, currentScope1, mSettings.debugwarnings); } catch (const std::runtime_error &) { reportError(tok1, Severity::debug, "simplifyUsingUnmatchedBodyEnd", "simplifyUsing: unmatched body end"); @@ -3106,9 +3106,9 @@ bool Tokenizer::simplifyUsing() continue; } if (inMemberFunc && memberFuncScope) { - if (!usingMatch(nameToken, scope, &tok1, scope1, currentScope1, memberFuncScope)) + if (!usingMatch(nameToken, scope, tok1, scope1, currentScope1, memberFuncScope)) continue; - } else if (!usingMatch(nameToken, scope, &tok1, scope1, currentScope1, nullptr)) + } else if (!usingMatch(nameToken, scope, tok1, scope1, currentScope1, nullptr)) continue; const auto nReplace = tokDistance(start, usingEnd); @@ -3749,9 +3749,9 @@ void Tokenizer::simplifyDoublePlusAndDoubleMinus() void Tokenizer::arraySize() { - auto getStrTok = [](Token* tok, bool addLength, Token** endStmt) -> Token* { + auto getStrTok = [](Token* tok, bool addLength, Token*& endStmt) -> Token* { if (addLength) { - *endStmt = tok->tokAt(5); + endStmt = tok->tokAt(5); return tok->tokAt(4); } if (Token::Match(tok, "%var% [ ] =")) { @@ -3762,7 +3762,7 @@ void Tokenizer::arraySize() tok = tok->next(); } if (Token::Match(tok, "%str%")) { - *endStmt = tok->tokAt(parCount + 1); + endStmt = tok->tokAt(parCount + 1); return tok; } } @@ -3781,7 +3781,7 @@ void Tokenizer::arraySize() } Token* endStmt{}; - if (const Token* strTok = getStrTok(tok, addlength, &endStmt)) { + if (const Token* strTok = getStrTok(tok, addlength, endStmt)) { const int sz = Token::getStrArraySize(strTok); tok->next()->insertToken(std::to_string(sz)); tok = endStmt; @@ -4162,10 +4162,10 @@ void VariableMap::addVariable(const std::string& varname, bool globalNamespace) it->second = ++mVarId; } -static bool setVarIdParseDeclaration(Token** tok, const VariableMap& variableMap, bool executableScope) +static bool setVarIdParseDeclaration(Token*& tok, const VariableMap& variableMap, bool executableScope) { - const Token* const tok1 = *tok; - Token* tok2 = *tok; + const Token* const tok1 = tok; + Token* tok2 = tok; if (!tok2->isName()) return false; @@ -4205,7 +4205,7 @@ static bool setVarIdParseDeclaration(Token** tok, const VariableMap& variableMap } } else if (tok2->isCpp() && ((TemplateSimplifier::templateParameters(tok2) > 0) || Token::simpleMatch(tok2, "< >") /* Ticket #4764 */)) { - const Token *start = *tok; + const Token *start = tok; if (Token::Match(start->previous(), "%or%|%oror%|&&|&|^|+|-|*|/")) return false; Token* const closingBracket = tok2->findClosingBracket(); @@ -4249,7 +4249,7 @@ static bool setVarIdParseDeclaration(Token** tok, const VariableMap& variableMap if (tok2) { bool isLambdaArg = false; { - const Token *tok3 = (*tok)->previous(); + const Token *tok3 = tok->previous(); if (tok3 && tok3->str() == ",") { while (tok3 && !Token::Match(tok3,";|(|[|{")) { if (Token::Match(tok3, ")|]")) @@ -4275,7 +4275,7 @@ static bool setVarIdParseDeclaration(Token** tok, const VariableMap& variableMap } - *tok = tok2; + tok = tok2; // In executable scopes, references must be assigned // Catching by reference is an exception @@ -4304,11 +4304,11 @@ static bool setVarIdParseDeclaration(Token** tok, const VariableMap& variableMap } -static void setVarIdStructMembers(Token **tok1, +static void setVarIdStructMembers(Token *&tok1, std::map>& structMembers, nonneg int &varId) { - Token *tok = *tok1; + Token *tok = tok1; if (Token::Match(tok, "%name% = { . %name% =|{")) { const nonneg int struct_varid = tok->varId(); @@ -4366,7 +4366,7 @@ static void setVarIdStructMembers(Token **tok1, } } // tok can't be null - *tok1 = tok; + tok1 = tok; } static bool setVarIdClassDeclaration(Token* const startToken, @@ -4434,7 +4434,7 @@ static bool setVarIdClassDeclaration(Token* const startToken, const std::unordered_map::const_iterator it = variableMap.map(false).find(tok->str()); if (it != variableMap.map(false).end()) { tok->varId(it->second); - setVarIdStructMembers(&tok, structMembers, variableMap.getVarId()); + setVarIdStructMembers(tok, structMembers, variableMap.getVarId()); } } } @@ -4472,7 +4472,7 @@ void Tokenizer::setVarIdClassFunction(const std::string &classname, const std::map::const_iterator it = varlist.find(tok2->str()); if (it != varlist.end()) { tok2->varId(it->second); - setVarIdStructMembers(&tok2, structMembers, varId_); + setVarIdStructMembers(tok2, structMembers, varId_); } } } @@ -4689,7 +4689,7 @@ void Tokenizer::setVarIdPass1() } try { /* Ticket #8151 */ - decl = setVarIdParseDeclaration(&tok2, variableMap, scopeStack.top().isExecutable); + decl = setVarIdParseDeclaration(tok2, variableMap, scopeStack.top().isExecutable); } catch (const Token * errTok) { syntaxError(errTok); } @@ -4852,7 +4852,7 @@ void Tokenizer::setVarIdPass1() const std::unordered_map::const_iterator it = variableMap.map(globalNamespace).find(tok->str()); if (it != variableMap.map(globalNamespace).end()) { tok->varId(it->second); - setVarIdStructMembers(&tok, structMembers, variableMap.getVarId()); + setVarIdStructMembers(tok, structMembers, variableMap.getVarId()); } } } else if (Token::Match(tok, "::|. %name%") && Token::Match(tok->previous(), ")|]|>|%name%")) { @@ -9760,7 +9760,7 @@ void Tokenizer::simplifyNamespaceStd() for (Token* tok = Token::findsimplematch(list.front(), "using namespace std ;"); tok; tok = tok->next()) { bool insert = false; if (Token::Match(tok, "enum class|struct| %name%| :|{")) { // Don't replace within enum definitions - skipEnumBody(&tok); + skipEnumBody(tok); } if (!tok->isName() || tok->isKeyword() || tok->isStandardType() || tok->varId()) continue; diff --git a/lib/tokenize.h b/lib/tokenize.h index 5eda6a888d1..e889ec0295b 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -538,7 +538,7 @@ class CPPCHECKLIB Tokenizer { void reportError(const Token* tok, const Severity severity, const std::string& id, const std::string& msg, bool inconclusive = false) const; void reportError(const std::list& callstack, Severity severity, const std::string& id, const std::string& msg, bool inconclusive = false) const; - bool duplicateTypedef(Token **tokPtr, const Token *name, const Token *typeDef) const; + bool duplicateTypedef(Token *&tokPtr, const Token *name, const Token *typeDef) const; void unsupportedTypedef(const Token *tok) const; diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index dcb0eb710bc..dc826e60290 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -8561,7 +8561,7 @@ static void valueFlowSmartPointer(TokenList &tokenlist, ErrorLogger & errorLogge static Library::Container::Yield findIteratorYield(Token* tok, const Token** ftok, const Settings &settings) { auto yield = astContainerYield(tok, ftok); - if (*ftok) + if (ftok && *ftok) return yield; if (!tok->astParent()) diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index d56db42fef9..7e44bf56a21 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -6568,7 +6568,8 @@ class TestSymbolDatabase : public TestFixture { " *PTRRELOC(&x) = &y;\n" "}"); ASSERT(db != nullptr); - ASSERT(db && !db->isFunction(Token::findsimplematch(tokenizer.tokens(), "PTRRELOC ( &"), &db->scopeList.back(), nullptr, nullptr, nullptr)); + const Token *funcStart, *argStart, *declEnd; + ASSERT(db && !db->isFunction(Token::findsimplematch(tokenizer.tokens(), "PTRRELOC ( &"), &db->scopeList.back(), funcStart, argStart, declEnd)); ASSERT(db->findScopeByName("set_cur_cpu_spec") != nullptr); ASSERT(db->findScopeByName("setup_cpu_spec") != nullptr); ASSERT(db->findScopeByName("PTRRELOC") == nullptr);