diff --git a/lib/check.h b/lib/check.h index 768cc889c62..019b77e148e 100644 --- a/lib/check.h +++ b/lib/check.h @@ -65,7 +65,7 @@ class CPPCHECKLIB Check { virtual void runChecks(const Tokenizer &, ErrorLogger *) = 0; /** get error messages */ - virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const = 0; + virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const = 0; /** class name, used to generate documentation */ const std::string& name() const { diff --git a/lib/check64bit.cpp b/lib/check64bit.cpp index e1e6f086ff3..6c45c68aaeb 100644 --- a/lib/check64bit.cpp +++ b/lib/check64bit.cpp @@ -36,12 +36,12 @@ // CWE ids used static const CWE CWE758(758U); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior -static bool is32BitIntegerReturn(const Function* func, const Settings* settings) +static bool is32BitIntegerReturn(const Function* func, const Settings& settings) { - if (settings->platform.sizeof_pointer != 8) + if (settings.platform.sizeof_pointer != 8) return false; const ValueType* vt = func->arg->valueType(); - return vt && vt->pointer == 0 && vt->isIntegral() && vt->getSizeOf(*settings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointer) == 4; + return vt && vt->pointer == 0 && vt->isIntegral() && vt->getSizeOf(settings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointer) == 4; } static bool isFunctionPointer(const Token* tok) @@ -53,7 +53,7 @@ static bool isFunctionPointer(const Token* tok) void Check64BitPortabilityImpl::pointerassignment() { - if (!mSettings->severity.isEnabled(Severity::portability)) + if (!mSettings.severity.isEnabled(Severity::portability)) return; logChecker("Check64BitPortability::pointerassignment"); // portability @@ -185,11 +185,11 @@ void Check64BitPortabilityImpl::returnIntegerError(const Token *tok) void Check64BitPortability::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - Check64BitPortabilityImpl check64BitPortability(&tokenizer, &tokenizer.getSettings(), errorLogger); + Check64BitPortabilityImpl check64BitPortability(&tokenizer, tokenizer.getSettings(), errorLogger); check64BitPortability.pointerassignment(); } -void Check64BitPortability::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void Check64BitPortability::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { Check64BitPortabilityImpl c(nullptr, settings, errorLogger); c.assignmentAddressToIntegerError(nullptr); diff --git a/lib/check64bit.h b/lib/check64bit.h index 1996d91ee23..160df94b990 100644 --- a/lib/check64bit.h +++ b/lib/check64bit.h @@ -51,7 +51,7 @@ class CPPCHECKLIB Check64BitPortability : public Check { /** @brief Run checks against the normal token list */ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { return "Check if there is 64-bit portability issues:\n" @@ -63,7 +63,7 @@ class CPPCHECKLIB Check64BitPortability : public Check { class CPPCHECKLIB Check64BitPortabilityImpl : public CheckImpl { public: /** This constructor is used when running checks. */ - Check64BitPortabilityImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + Check64BitPortabilityImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** Check for pointer assignment */ diff --git a/lib/checkassert.cpp b/lib/checkassert.cpp index 5242b595e67..3ae06984c7b 100644 --- a/lib/checkassert.cpp +++ b/lib/checkassert.cpp @@ -41,7 +41,7 @@ static const CWE CWE398(398U); // Indicator of Poor Code Quality void CheckAssertImpl::assertWithSideEffects() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckAssert::assertWithSideEffects"); // warning @@ -58,7 +58,7 @@ void CheckAssertImpl::assertWithSideEffects() checkVariableAssignment(tmp, tok->scope()); if (tmp->tokType() != Token::eFunction) { - if (const Library::Function* f = mSettings->library.getFunction(tmp)) { + if (const Library::Function* f = mSettings.library.getFunction(tmp)) { if (f->isconst || f->ispure) continue; if (Library::getContainerYield(tmp->next()) != Library::Container::Yield::NO_YIELD) // bailout, assume read access @@ -73,7 +73,7 @@ void CheckAssertImpl::assertWithSideEffects() f->containerYield == Library::Container::Yield::END_ITERATOR || f->containerYield == Library::Container::Yield::ITERATOR) continue; - sideEffectInAssertError(tmp, mSettings->library.getFunctionName(tmp)); + sideEffectInAssertError(tmp, mSettings.library.getFunctionName(tmp)); } continue; } @@ -180,11 +180,11 @@ bool CheckAssertImpl::inSameScope(const Token* returnTok, const Token* assignTok void CheckAssert::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckAssertImpl checkAssert(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckAssertImpl checkAssert(&tokenizer, tokenizer.getSettings(), errorLogger); checkAssert.assertWithSideEffects(); } -void CheckAssert::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckAssert::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckAssertImpl c(nullptr, settings, errorLogger); c.sideEffectInAssertError(nullptr, "function"); diff --git a/lib/checkassert.h b/lib/checkassert.h index 3fac8f5af83..6a4e1f45de2 100644 --- a/lib/checkassert.h +++ b/lib/checkassert.h @@ -48,7 +48,7 @@ class CPPCHECKLIB CheckAssert : public Check { private: /** run checks, the token list is not simplified */ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { return "Warn if there are side effects in assert statements (since this cause different behaviour in debug/release builds).\n"; @@ -57,7 +57,7 @@ class CPPCHECKLIB CheckAssert : public Check { class CPPCHECKLIB CheckAssertImpl : public CheckImpl { public: - CheckAssertImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckAssertImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} void assertWithSideEffects(); diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 0d3cae1c2fa..48ca74253a5 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -204,9 +204,9 @@ static bool variableIsUsedInScope(const Token* start, nonneg int varId, const Sc void CheckAutoVariablesImpl::assignFunctionArg() { - const bool printStyle = mSettings->severity.isEnabled(Severity::style); - const bool printWarning = mSettings->severity.isEnabled(Severity::warning); - if (!printStyle && !printWarning && !mSettings->isPremiumEnabled("uselessAssignmentPtrArg")) + const bool printStyle = mSettings.severity.isEnabled(Severity::style); + const bool printWarning = mSettings.severity.isEnabled(Severity::warning); + if (!printStyle && !printWarning && !mSettings.isPremiumEnabled("uselessAssignmentPtrArg")) return; logChecker("CheckAutoVariables::assignFunctionArg"); // style,warning @@ -284,7 +284,7 @@ void CheckAutoVariablesImpl::autoVariables() { logChecker("CheckAutoVariables::autoVariables"); - const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive); + const bool printInconclusive = mSettings.certainty.isEnabled(Certainty::inconclusive); const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) { @@ -295,27 +295,27 @@ void CheckAutoVariablesImpl::autoVariables() } // Critical assignment const Token* rhs{}; - if (Token::Match(tok, "[;{}] %var% =") && isRefPtrArg(tok->next()) && isAutoVariableRHS(tok->tokAt(2)->astOperand2(), *mSettings)) { + if (Token::Match(tok, "[;{}] %var% =") && isRefPtrArg(tok->next()) && isAutoVariableRHS(tok->tokAt(2)->astOperand2(), mSettings)) { checkAutoVariableAssignment(tok->next(), false); - } else if (Token::Match(tok, "[;{}] * %var% =") && isPtrArg(tok->tokAt(2)) && isAutoVariableRHS(tok->tokAt(3)->astOperand2(), *mSettings)) { + } else if (Token::Match(tok, "[;{}] * %var% =") && isPtrArg(tok->tokAt(2)) && isAutoVariableRHS(tok->tokAt(3)->astOperand2(), mSettings)) { const Token* lhs = tok->tokAt(2); bool inconclusive = false; if (!hasOverloadedAssignment(lhs, inconclusive) || (printInconclusive && inconclusive)) checkAutoVariableAssignment(tok->next(), inconclusive); tok = tok->tokAt(4); - } else if (isMemberAssignment(tok, rhs, *mSettings)) { + } else if (isMemberAssignment(tok, rhs, mSettings)) { const Token* lhs = tok->tokAt(3); bool inconclusive = false; if (!hasOverloadedAssignment(lhs, inconclusive) || (printInconclusive && inconclusive)) checkAutoVariableAssignment(tok->next(), inconclusive); tok = rhs; } else if (Token::Match(tok, "[;{}] %var% [") && Token::simpleMatch(tok->linkAt(2), "] =") && - (isPtrArg(tok->next()) || isArrayArg(tok->next(), *mSettings)) && - isAutoVariableRHS(tok->linkAt(2)->next()->astOperand2(), *mSettings)) { + (isPtrArg(tok->next()) || isArrayArg(tok->next(), mSettings)) && + isAutoVariableRHS(tok->linkAt(2)->next()->astOperand2(), mSettings)) { errorAutoVariableAssignment(tok->next(), false); } // Invalid pointer deallocation - else if ((Token::Match(tok, "%name% ( %var%|%str% ) ;") && mSettings->library.getDeallocFuncInfo(tok)) || + else if ((Token::Match(tok, "%name% ( %var%|%str% ) ;") && mSettings.library.getDeallocFuncInfo(tok)) || (tok->isCpp() && Token::Match(tok, "delete [| ]| (| %var%|%str% !!["))) { tok = Token::findmatch(tok->next(), "%var%|%str%"); if (Token::simpleMatch(tok->astParent(), ".")) @@ -333,7 +333,7 @@ void CheckAutoVariablesImpl::autoVariables() } } } - } else if ((Token::Match(tok, "%name% ( & %var% ) ;") && mSettings->library.getDeallocFuncInfo(tok)) || + } else if ((Token::Match(tok, "%name% ( & %var% ) ;") && mSettings.library.getDeallocFuncInfo(tok)) || (tok->isCpp() && Token::Match(tok, "delete [| ]| (| & %var% !!["))) { tok = Token::findmatch(tok->next(), "%var%"); if (isAutoVar(tok)) @@ -564,7 +564,7 @@ static bool isAssignedToNonLocal(const Token* tok) void CheckAutoVariablesImpl::checkVarLifetimeScope(const Token * start, const Token * end) { - const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive); + const bool printInconclusive = mSettings.certainty.isEnabled(Certainty::inconclusive); if (!start) return; const Scope * scope = start->scope(); @@ -577,7 +577,7 @@ void CheckAutoVariablesImpl::checkVarLifetimeScope(const Token * start, const To for (const Token *tok = start; tok && tok != end; tok = tok->next()) { // Return reference from function if (returnRef && Token::simpleMatch(tok->astParent(), "return")) { - for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(tok, *mSettings, true)) { + for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(tok, mSettings, true)) { if (!printInconclusive && lt.inconclusive) continue; const Variable* var = lt.token->variable(); @@ -586,7 +586,7 @@ void CheckAutoVariablesImpl::checkVarLifetimeScope(const Token * start, const To errorReturnReference(tok, lt.errorPath, lt.inconclusive); break; } - if (isDeadTemporary(lt.token, nullptr, mSettings->library)) { + if (isDeadTemporary(lt.token, nullptr, mSettings.library)) { errorReturnTempReference(tok, lt.errorPath, lt.inconclusive); break; } @@ -597,18 +597,18 @@ void CheckAutoVariablesImpl::checkVarLifetimeScope(const Token * start, const To tok->variable()->declarationId() == tok->varId() && tok->variable()->isStatic() && !tok->variable()->isArgument()) { ErrorPath errorPath; - const Variable *var = ValueFlow::getLifetimeVariable(tok, errorPath, *mSettings); + const Variable *var = ValueFlow::getLifetimeVariable(tok, errorPath, mSettings); if (var && isInScope(var->nameToken(), tok->scope())) { errorDanglingReference(tok, var, std::move(errorPath)); continue; } // Reference to temporary } else if (tok->variable() && (tok->variable()->isReference() || tok->variable()->isRValueReference())) { - for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(getParentLifetime(tok), *mSettings)) { + for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(getParentLifetime(tok), mSettings)) { if (!printInconclusive && lt.inconclusive) continue; const Token * tokvalue = lt.token; - if (isDeadTemporary(tokvalue, tok, mSettings->library)) { + if (isDeadTemporary(tokvalue, tok, mSettings.library)) { errorDanglingTempReference(tok, lt.errorPath, lt.inconclusive); break; } @@ -622,23 +622,23 @@ void CheckAutoVariablesImpl::checkVarLifetimeScope(const Token * start, const To continue; if (!printInconclusive && val.isInconclusive()) continue; - const Token* parent = getParentLifetime(val.tokvalue, mSettings->library); + const Token* parent = getParentLifetime(val.tokvalue, mSettings.library); if (!exprs.insert(parent).second) continue; - for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(parent, *mSettings, escape || isAssignedToNonLocal(tok))) { + for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(parent, mSettings, escape || isAssignedToNonLocal(tok))) { const Token * tokvalue = lt.token; if (val.isLocalLifetimeValue()) { if (escape) { if (getPointerDepth(tok) < getPointerDepth(tokvalue)) continue; - if (!ValueFlow::isLifetimeBorrowed(tok, *mSettings)) + if (!ValueFlow::isLifetimeBorrowed(tok, mSettings)) continue; if (tokvalue->exprId() == tok->exprId() && !(tok->variable() && tok->variable()->isArray()) && !astIsContainerView(tok->astParent())) continue; if ((tokvalue->variable() && !isEscapedReference(tokvalue->variable()) && isInScope(tokvalue->variable()->nameToken(), scope)) || - isDeadTemporary(tokvalue, nullptr, mSettings->library)) { + isDeadTemporary(tokvalue, nullptr, mSettings.library)) { if (!diag(tokvalue)) errorReturnDanglingLifetime(tok, &val); break; @@ -647,7 +647,7 @@ void CheckAutoVariablesImpl::checkVarLifetimeScope(const Token * start, const To errorInvalidLifetime(tok, &val); break; } else if (!tokvalue->variable() && - isDeadTemporary(tokvalue, tok, mSettings->library)) { + isDeadTemporary(tokvalue, tok, mSettings.library)) { if (!diag(tokvalue)) errorDanglingTemporaryLifetime(tok, &val, tokvalue); break; @@ -665,7 +665,7 @@ void CheckAutoVariablesImpl::checkVarLifetimeScope(const Token * start, const To } else if (tok->variable() && tok->variable()->declarationId() == tok->varId()) { var = tok->variable(); } - if (!ValueFlow::isLifetimeBorrowed(tok, *mSettings)) + if (!ValueFlow::isLifetimeBorrowed(tok, mSettings)) continue; const Token* nextTok = nextAfterAstRightmostLeaf(tok->astTop()); if (!nextTok) @@ -677,7 +677,7 @@ void CheckAutoVariablesImpl::checkVarLifetimeScope(const Token * start, const To var->valueType() ? var->valueType()->pointer : 0, var->declarationId(), var->isGlobal(), - *mSettings)) { + mSettings)) { if (!diag(tok2)) errorDanglngLifetime(tok2, &val, var->isLocal()); break; @@ -819,13 +819,13 @@ void CheckAutoVariablesImpl::errorInvalidDeallocation(const Token *tok, const Va void CheckAutoVariables::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckAutoVariablesImpl checkAutoVariables(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckAutoVariablesImpl checkAutoVariables(&tokenizer, tokenizer.getSettings(), errorLogger); checkAutoVariables.assignFunctionArg(); checkAutoVariables.autoVariables(); checkAutoVariables.checkVarLifetime(); } -void CheckAutoVariables::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckAutoVariables::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckAutoVariablesImpl c(nullptr,settings,errorLogger); c.errorAutoVariableAssignment(nullptr, false); diff --git a/lib/checkautovariables.h b/lib/checkautovariables.h index 39e6ceb10d5..77deef00113 100644 --- a/lib/checkautovariables.h +++ b/lib/checkautovariables.h @@ -54,7 +54,7 @@ class CPPCHECKLIB CheckAutoVariables : public Check { /** @brief Run checks against the normal token list */ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { return "A pointer to a variable is only valid as long as the variable is in scope.\n" @@ -72,7 +72,7 @@ class CPPCHECKLIB CheckAutoVariablesImpl : public CheckImpl { public: /** This constructor is used when running checks. */ - CheckAutoVariablesImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckAutoVariablesImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** assign function argument */ diff --git a/lib/checkbool.cpp b/lib/checkbool.cpp index e4f55f26085..a216307ad2e 100644 --- a/lib/checkbool.cpp +++ b/lib/checkbool.cpp @@ -45,7 +45,7 @@ static bool isBool(const Variable* var) //--------------------------------------------------------------------------- void CheckBoolImpl::checkIncrementBoolean() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("incrementboolean")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("incrementboolean")) return; logChecker("CheckBool::checkIncrementBoolean"); // style @@ -85,11 +85,11 @@ static bool isConvertedToBool(const Token* tok) //--------------------------------------------------------------------------- void CheckBoolImpl::checkBitwiseOnBoolean() { - if (!mSettings->isPremiumEnabled("bitwiseOnBoolean") && - !mSettings->severity.isEnabled(Severity::style) && + if (!mSettings.isPremiumEnabled("bitwiseOnBoolean") && + !mSettings.severity.isEnabled(Severity::style) && // danmar: this is inconclusive because I don't like that there are // warnings for calculations. Example: set_flag(a & b); - !mSettings->certainty.isEnabled(Certainty::inconclusive)) + !mSettings.certainty.isEnabled(Certainty::inconclusive)) return; logChecker("CheckBool::checkBitwiseOnBoolean"); // style,inconclusive @@ -116,7 +116,7 @@ void CheckBoolImpl::checkBitwiseOnBoolean() if (tok->str() == "|" && !isConvertedToBool(tok) && !(isBoolOp1 && isBoolOp2)) continue; // first operand will always be evaluated - if (!isConstExpression(tok->astOperand2(), mSettings->library)) + if (!isConstExpression(tok->astOperand2(), mSettings.library)) continue; if (tok->astOperand2()->variable() && tok->astOperand2()->variable()->nameToken() == tok->astOperand2()) continue; @@ -146,7 +146,7 @@ void CheckBoolImpl::bitwiseOnBooleanError(const Token* tok, const std::string& e void CheckBoolImpl::checkComparisonOfBoolWithInt() { - if (!mSettings->severity.isEnabled(Severity::warning) || !mTokenizer->isCPP()) + if (!mSettings.severity.isEnabled(Severity::warning) || !mTokenizer->isCPP()) return; logChecker("CheckBool::checkComparisonOfBoolWithInt"); // warning,c++ @@ -197,7 +197,7 @@ static bool tokenIsFunctionReturningBool(const Token* tok) void CheckBoolImpl::checkComparisonOfFuncReturningBool() { - if (!mSettings->severity.isEnabled(Severity::style)) + if (!mSettings.severity.isEnabled(Severity::style)) return; if (!mTokenizer->isCPP()) @@ -263,7 +263,7 @@ void CheckBoolImpl::comparisonOfTwoFuncsReturningBoolError(const Token *tok, con void CheckBoolImpl::checkComparisonOfBoolWithBool() { - if (!mSettings->severity.isEnabled(Severity::style)) + if (!mSettings.severity.isEnabled(Severity::style)) return; if (!mTokenizer->isCPP()) @@ -335,7 +335,7 @@ void CheckBoolImpl::assignBoolToPointerError(const Token *tok) //----------------------------------------------------------------------------- void CheckBoolImpl::checkComparisonOfBoolExpressionWithInt() { - if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("compareBoolExpressionWithInt")) + if (!mSettings.severity.isEnabled(Severity::warning) && !mSettings.isPremiumEnabled("compareBoolExpressionWithInt")) return; logChecker("CheckBool::checkComparisonOfBoolExpressionWithInt"); // warning @@ -373,13 +373,13 @@ void CheckBoolImpl::checkComparisonOfBoolExpressionWithInt() if (astIsBool(numTok)) continue; - const ValueFlow::Value *minval = numTok->getValueLE(0, *mSettings); + const ValueFlow::Value *minval = numTok->getValueLE(0, mSettings); if (minval && minval->intvalue == 0 && (numInRhs ? Token::Match(tok, ">|==|!=") : Token::Match(tok, "<|==|!="))) minval = nullptr; - const ValueFlow::Value *maxval = numTok->getValueGE(1, *mSettings); + const ValueFlow::Value *maxval = numTok->getValueGE(1, mSettings); if (maxval && maxval->intvalue == 1 && (numInRhs ? Token::Match(tok, "<|==|!=") : Token::Match(tok, ">|==|!="))) @@ -460,7 +460,7 @@ void CheckBoolImpl::checkAssignBoolToFloat() { if (!mTokenizer->isCPP()) return; - if (!mSettings->severity.isEnabled(Severity::style)) + if (!mSettings.severity.isEnabled(Severity::style)) return; logChecker("CheckBool::checkAssignBoolToFloat"); // style,c++ const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); @@ -481,7 +481,7 @@ void CheckBoolImpl::assignBoolToFloatError(const Token *tok) void CheckBoolImpl::returnValueOfFunctionReturningBool() { - if (!mSettings->severity.isEnabled(Severity::style)) + if (!mSettings.severity.isEnabled(Severity::style)) return; logChecker("CheckBool::returnValueOfFunctionReturningBool"); // style @@ -500,7 +500,7 @@ void CheckBoolImpl::returnValueOfFunctionReturningBool() else if (tok->scope() && tok->scope()->isClassOrStruct()) tok = tok->scope()->bodyEnd; else if (Token::simpleMatch(tok, "return") && tok->astOperand1() && - (tok->astOperand1()->getValueGE(2, *mSettings) || tok->astOperand1()->getValueLE(-1, *mSettings)) && + (tok->astOperand1()->getValueGE(2, mSettings) || tok->astOperand1()->getValueLE(-1, mSettings)) && !(tok->astOperand1()->astOperand1() && Token::Match(tok->astOperand1(), "&|%or%"))) returnValueBoolError(tok); } @@ -514,7 +514,7 @@ void CheckBoolImpl::returnValueBoolError(const Token *tok) void CheckBool::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckBoolImpl checkBool(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckBoolImpl checkBool(&tokenizer, tokenizer.getSettings(), errorLogger); // Checks checkBool.checkComparisonOfBoolExpressionWithInt(); @@ -529,7 +529,7 @@ void CheckBool::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) checkBool.checkBitwiseOnBoolean(); } -void CheckBool::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckBool::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckBoolImpl c(nullptr, settings, errorLogger); c.assignBoolToPointerError(nullptr); diff --git a/lib/checkbool.h b/lib/checkbool.h index 607d9c4a4b7..2d523732682 100644 --- a/lib/checkbool.h +++ b/lib/checkbool.h @@ -48,7 +48,7 @@ class CPPCHECKLIB CheckBool : public Check { /** @brief Run checks against the normal token list */ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { return "Boolean type checks\n" @@ -67,7 +67,7 @@ class CPPCHECKLIB CheckBoolImpl : public CheckImpl { public: /** @brief This constructor is used when running checks. */ - CheckBoolImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckBoolImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** @brief %Check for comparison of function returning bool*/ diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 592e4268f58..7f0612963b9 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -323,7 +323,7 @@ void CheckBufferOverrunImpl::arrayIndex() ErrorPath errorPath; bool mightBeLarger = false; MathLib::bigint path = 0; - if (!getDimensionsEtc(tok->astOperand1(), *mSettings, dimensions, errorPath, mightBeLarger, path)) + if (!getDimensionsEtc(tok->astOperand1(), mSettings, dimensions, errorPath, mightBeLarger, path)) continue; const Variable* const var = array->variable(); @@ -331,7 +331,7 @@ void CheckBufferOverrunImpl::arrayIndex() const Token* changeTok = var->scope()->bodyStart; bool isChanged = false; while ((changeTok = findVariableChanged(changeTok->next(), var->scope()->bodyEnd, /*indirect*/ 0, var->declarationId(), - /*globalvar*/ false, *mSettings))) { + /*globalvar*/ false, mSettings))) { if (!Token::simpleMatch(changeTok->astParent(), "[")) { isChanged = true; break; @@ -353,7 +353,7 @@ void CheckBufferOverrunImpl::arrayIndex() bool neg = false; std::vector negativeIndexes; for (const Token * indexToken : indexTokens) { - const ValueFlow::Value *negativeValue = indexToken->getValueLE(-1, *mSettings); + const ValueFlow::Value *negativeValue = indexToken->getValueLE(-1, mSettings); if (negativeValue) { negativeIndexes.emplace_back(*negativeValue); neg = true; @@ -418,7 +418,7 @@ void CheckBufferOverrunImpl::arrayIndexError(const Token* tok, const Token *condition = nullptr; const ValueFlow::Value *index = nullptr; for (const ValueFlow::Value& indexValue : indexes) { - if (!indexValue.errorSeverity() && !mSettings->severity.isEnabled(Severity::warning)) + if (!indexValue.errorSeverity() && !mSettings.severity.isEnabled(Severity::warning)) return; if (indexValue.condition) condition = indexValue.condition; @@ -446,7 +446,7 @@ void CheckBufferOverrunImpl::negativeIndexError(const Token* tok, const Token *condition = nullptr; const ValueFlow::Value *negativeValue = nullptr; for (const ValueFlow::Value& indexValue : indexes) { - if (!indexValue.errorSeverity() && !mSettings->severity.isEnabled(Severity::warning)) + if (!indexValue.errorSeverity() && !mSettings.severity.isEnabled(Severity::warning)) return; if (indexValue.condition) condition = indexValue.condition; @@ -466,7 +466,7 @@ void CheckBufferOverrunImpl::negativeIndexError(const Token* tok, void CheckBufferOverrunImpl::pointerArithmetic() { - if (!mSettings->severity.isEnabled(Severity::portability) && !mSettings->isPremiumEnabled("pointerOutOfBounds")) + if (!mSettings.severity.isEnabled(Severity::portability) && !mSettings.isPremiumEnabled("pointerOutOfBounds")) return; logChecker("CheckBufferOverrun::pointerArithmetic"); // portability @@ -497,7 +497,7 @@ void CheckBufferOverrunImpl::pointerArithmetic() ErrorPath errorPath; bool mightBeLarger = false; MathLib::bigint path = 0; - if (!getDimensionsEtc(arrayToken, *mSettings, dimensions, errorPath, mightBeLarger, path)) + if (!getDimensionsEtc(arrayToken, mSettings, dimensions, errorPath, mightBeLarger, path)) continue; if (tok->str() == "+") { @@ -510,7 +510,7 @@ void CheckBufferOverrunImpl::pointerArithmetic() pointerArithmeticError(tok, indexToken, &indexValues.front()); } - if (const ValueFlow::Value *neg = indexToken->getValueLE(-1, *mSettings)) + if (const ValueFlow::Value *neg = indexToken->getValueLE(-1, mSettings)) pointerArithmeticError(tok, indexToken, neg); } else if (tok->str() == "-") { if (arrayToken->variable() && arrayToken->variable()->isArgument()) @@ -520,7 +520,7 @@ void CheckBufferOverrunImpl::pointerArithmetic() while (Token::Match(array, ".|::")) array = array->astOperand2(); if (array->variable() && array->variable()->isArray()) { - const ValueFlow::Value *v = indexToken->getValueGE(1, *mSettings); + const ValueFlow::Value *v = indexToken->getValueGE(1, mSettings); if (v) pointerArithmeticError(tok, indexToken, v); } @@ -578,9 +578,9 @@ ValueFlow::Value CheckBufferOverrunImpl::getBufferSize(const Token *bufTok) cons v.valueType = ValueFlow::Value::ValueType::BUFFER_SIZE; if (var->isPointerArray()) - v.intvalue = dim * mSettings->platform.sizeof_pointer; + v.intvalue = dim * mSettings.platform.sizeof_pointer; else { - const size_t typeSize = bufTok->valueType()->getSizeOf(*mSettings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointee); + const size_t typeSize = bufTok->valueType()->getSizeOf(mSettings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointee); v.intvalue = dim * typeSize; } @@ -643,13 +643,13 @@ void CheckBufferOverrunImpl::bufferOverflow() for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "%name% (") || Token::simpleMatch(tok, ") {")) continue; - if (!mSettings->library.hasminsize(tok)) + if (!mSettings.library.hasminsize(tok)) continue; const std::vector args = getArguments(tok); for (int argnr = 0; argnr < args.size(); ++argnr) { if (!args[argnr]->valueType() || args[argnr]->valueType()->pointer == 0) continue; - const std::vector *minsizes = mSettings->library.argminsizes(tok, argnr + 1); + const std::vector *minsizes = mSettings.library.argminsizes(tok, argnr + 1); if (!minsizes || minsizes->empty()) continue; // Get buffer size.. @@ -682,7 +682,7 @@ void CheckBufferOverrunImpl::bufferOverflow() } } const bool error = std::none_of(minsizes->begin(), minsizes->end(), [&](const Library::ArgumentChecks::MinSize &minsize) { - return checkBufferSize(tok, minsize, args, bufferSize.intvalue, *mSettings, mTokenizer); + return checkBufferSize(tok, minsize, args, bufferSize.intvalue, mSettings, mTokenizer); }); if (error) bufferOverflowError(args[argnr], &bufferSize, Certainty::normal); @@ -700,7 +700,7 @@ void CheckBufferOverrunImpl::bufferOverflowError(const Token *tok, const ValueFl void CheckBufferOverrunImpl::arrayIndexThenCheck() { - if (!mSettings->severity.isEnabled(Severity::style)) + if (!mSettings.severity.isEnabled(Severity::style)) return; logChecker("CheckBufferOverrun::arrayIndexThenCheck"); // style @@ -758,7 +758,7 @@ void CheckBufferOverrunImpl::arrayIndexThenCheckError(const Token *tok, const st void CheckBufferOverrunImpl::stringNotZeroTerminated() { // this is currently 'inconclusive'. See TestBufferOverrun::terminateStrncpy3 - if (!mSettings->severity.isEnabled(Severity::warning) || !mSettings->certainty.isEnabled(Certainty::inconclusive)) + if (!mSettings.severity.isEnabled(Severity::warning) || !mSettings.certainty.isEnabled(Certainty::inconclusive)) return; logChecker("CheckBufferOverrun::stringNotZeroTerminated"); // warning,inconclusive @@ -797,7 +797,7 @@ void CheckBufferOverrunImpl::stringNotZeroTerminated() const Token *rhs = tok2->next()->astOperand2(); if (!rhs || !rhs->hasKnownIntValue() || rhs->getKnownIntValue() != 0) continue; - if (isSameExpression(false, args[0], tok2->link()->astOperand1(), *mSettings, false, false)) + if (isSameExpression(false, args[0], tok2->link()->astOperand1(), mSettings, false, false)) isZeroTerminated = true; } if (isZeroTerminated) @@ -824,7 +824,7 @@ void CheckBufferOverrunImpl::terminateStrncpyError(const Token *tok, const std:: void CheckBufferOverrunImpl::argumentSize() { // Check '%type% x[10]' arguments - if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("argumentSize")) + if (!mSettings.severity.isEnabled(Severity::warning) && !mSettings.isPremiumEnabled("argumentSize")) return; logChecker("CheckBufferOverrun::argumentSize"); // warning @@ -990,7 +990,7 @@ Check::FileInfo * CheckBufferOverrun::loadFileInfoFromXml(const tinyxml2::XMLEle /** @brief Analyse all file infos for all TU */ bool CheckBufferOverrun::analyseWholeProgram(const CTU::FileInfo &ctu, const std::list &fileInfo, const Settings& settings, ErrorLogger &errorLogger) { - CheckBufferOverrunImpl dummy(nullptr, &settings, &errorLogger); + CheckBufferOverrunImpl dummy(nullptr, settings, &errorLogger); dummy. logChecker("CheckBufferOverrun::analyseWholeProgram"); @@ -1096,7 +1096,7 @@ void CheckBufferOverrunImpl::objectIndex() continue; } if (obj->valueType() && var->valueType() && (obj->isCast() || (obj->isCpp() && isCPPCast(obj)) || obj->valueType()->pointer)) { // allow cast to a different type - const auto varSize = var->valueType()->getSizeOf(*mSettings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointee); + const auto varSize = var->valueType()->getSizeOf(mSettings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointee); if (varSize == 0) continue; if (obj->valueType()->type != var->valueType()->type) { @@ -1176,7 +1176,7 @@ void CheckBufferOverrunImpl::negativeArraySize() const Token* const nameToken = var->nameToken(); if (!Token::Match(nameToken, "%var% [") || !nameToken->next()->astOperand2()) continue; - const ValueFlow::Value* sz = nameToken->next()->astOperand2()->getValueLE(-1, *mSettings); + const ValueFlow::Value* sz = nameToken->next()->astOperand2()->getValueLE(-1, mSettings); // don't warn about constant negative index because that is a compiler error if (sz && isVLAIndex(nameToken->next()->astOperand2())) negativeArraySizeError(nameToken); @@ -1189,7 +1189,7 @@ void CheckBufferOverrunImpl::negativeArraySize() const Token* valOperand = tok->astOperand1()->astOperand2(); if (!valOperand) continue; - const ValueFlow::Value* sz = valOperand->getValueLE(-1, *mSettings); + const ValueFlow::Value* sz = valOperand->getValueLE(-1, mSettings); if (sz) negativeMemoryAllocationSizeError(tok, sz); } @@ -1216,7 +1216,7 @@ void CheckBufferOverrunImpl::negativeMemoryAllocationSizeError(const Token* tok, void CheckBufferOverrun::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckBufferOverrunImpl checkBufferOverrun(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckBufferOverrunImpl checkBufferOverrun(&tokenizer, tokenizer.getSettings(), errorLogger); checkBufferOverrun.arrayIndex(); checkBufferOverrun.pointerArithmetic(); checkBufferOverrun.bufferOverflow(); @@ -1227,7 +1227,7 @@ void CheckBufferOverrun::runChecks(const Tokenizer &tokenizer, ErrorLogger *erro checkBufferOverrun.negativeArraySize(); } -void CheckBufferOverrun::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckBufferOverrun::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckBufferOverrunImpl c(nullptr, settings, errorLogger); c.arrayIndexError(nullptr, std::vector(), std::vector()); diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index fdf47121bb8..2b43d575dec 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -72,7 +72,7 @@ class CPPCHECKLIB CheckBufferOverrun : public Check { /** @brief Analyse all file infos for all TU */ bool analyseWholeProgram(const CTU::FileInfo &ctu, const std::list &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; Check::FileInfo * loadFileInfoFromXml(const tinyxml2::XMLElement *xmlElement) const override; @@ -96,7 +96,7 @@ class CPPCHECKLIB CheckBufferOverrunImpl : public CheckImpl { public: /** This constructor is used when running checks. */ - CheckBufferOverrunImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckBufferOverrunImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} void arrayIndex(); diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index c5b8507f301..d7eb9b43b35 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -106,7 +106,7 @@ static bool isVclTypeInit(const Type *type) } //--------------------------------------------------------------------------- -CheckClassImpl::CheckClassImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) +CheckClassImpl::CheckClassImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger), mSymbolDatabase(tokenizer?tokenizer->getSymbolDatabase():nullptr) {} @@ -140,7 +140,7 @@ bool CheckClassImpl::isInitialized(const Usage& usage, FunctionType funcType) co const Token* ctt = var.valueType()->containerTypeToken; if (!ctt->isStandardType() && (!ctt->type() || ctt->type()->needInitialization != Type::NeedInitialization::True) && - !mSettings->library.podtype(ctt->str())) // TODO: handle complex type expression + !mSettings.library.podtype(ctt->str())) // TODO: handle complex type expression return true; } else @@ -201,16 +201,16 @@ void CheckClassImpl::handleUnionMembers(std::vector& usageList) void CheckClassImpl::constructors() { - const bool printStyle = mSettings->severity.isEnabled(Severity::style); - const bool printWarnings = mSettings->severity.isEnabled(Severity::warning); - if (!printStyle && !printWarnings && !mSettings->isPremiumEnabled("uninitMemberVar")) + const bool printStyle = mSettings.severity.isEnabled(Severity::style); + const bool printWarnings = mSettings.severity.isEnabled(Severity::warning); + if (!printStyle && !printWarnings && !mSettings.isPremiumEnabled("uninitMemberVar")) return; logChecker("CheckClass::checkConstructors"); // style,warning - const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive); + const bool printInconclusive = mSettings.certainty.isEnabled(Certainty::inconclusive); for (const Scope * scope : mSymbolDatabase->classAndStructScopes) { - if (mSettings->hasLib("vcl") && isVclTypeInit(scope->definedType)) + if (mSettings.hasLib("vcl") && isVclTypeInit(scope->definedType)) continue; const bool unusedTemplate = Token::simpleMatch(scope->classDef->previous(), ">"); @@ -315,9 +315,9 @@ void CheckClassImpl::constructors() } } - if (classNameUsed && mSettings->library.getTypeCheck("operatorEqVarError", var.getTypeName()) != Library::TypeCheck::suppress) + if (classNameUsed && mSettings.library.getTypeCheck("operatorEqVarError", var.getTypeName()) != Library::TypeCheck::suppress) operatorEqVarError(func.token, scope->className, var.name(), missingCopy); - } else if (func.access != AccessControl::Private || mSettings->standards.cpp >= Standards::CPP11) { + } else if (func.access != AccessControl::Private || mSettings.standards.cpp >= Standards::CPP11) { // If constructor is not in scope then we maybe using a constructor from a different template specialization if (!precedes(scope->bodyStart, func.tokenDef)) continue; @@ -347,7 +347,7 @@ void CheckClassImpl::constructors() // Variables with default initializers bool hasAnyDefaultInit = false; bool hasAnySelfInit = false; - const bool cpp14OrLater = mSettings->standards.cpp >= Standards::CPP14; + const bool cpp14OrLater = mSettings.standards.cpp >= Standards::CPP14; for (Usage& usage : usageList) { const Variable& var = *usage.var; @@ -387,7 +387,7 @@ static bool isPermissibleConversion(const std::string& type) void CheckClassImpl::checkExplicitConstructors() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("noExplicitConstructor")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("noExplicitConstructor")) return; logChecker("CheckClass::checkExplicitConstructors"); // style @@ -405,7 +405,7 @@ void CheckClassImpl::checkExplicitConstructors() // Abstract classes can't be instantiated. But if there is C++11 // "misuse" by derived classes then these constructors must be explicit. - if (isAbstractClass && mSettings->standards.cpp >= Standards::CPP11) + if (isAbstractClass && mSettings.standards.cpp >= Standards::CPP11) continue; for (const Function &func : scope->functionList) { @@ -456,7 +456,7 @@ static bool hasNonCopyableBase(const Scope *scope, bool *unknown) void CheckClassImpl::copyconstructors() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckClass::checkCopyConstructors"); // warning @@ -471,7 +471,7 @@ void CheckClassImpl::copyconstructors() const Token* tok = func.token->linkAt(1); for (const Token* const end = func.functionScope->bodyStart; tok != end; tok = tok->next()) { if (Token::Match(tok, "%var% ( new") || - (Token::Match(tok, "%var% ( %name% (") && mSettings->library.getAllocFuncInfo(tok->tokAt(2)))) { + (Token::Match(tok, "%var% ( %name% (") && mSettings.library.getAllocFuncInfo(tok->tokAt(2)))) { const Variable* var = tok->variable(); if (var && var->isPointer() && var->scope() == scope) allocatedVars[tok->varId()] = tok; @@ -479,7 +479,7 @@ void CheckClassImpl::copyconstructors() } for (const Token* const end = func.functionScope->bodyEnd; tok != end; tok = tok->next()) { if (Token::Match(tok, "%var% = new") || - (Token::Match(tok, "%var% = %name% (") && mSettings->library.getAllocFuncInfo(tok->tokAt(2)))) { + (Token::Match(tok, "%var% = %name% (") && mSettings.library.getAllocFuncInfo(tok->tokAt(2)))) { const Variable* var = tok->variable(); if (var && var->isPointer() && var->scope() == scope && !var->isStatic()) allocatedVars[tok->varId()] = tok; @@ -490,7 +490,7 @@ void CheckClassImpl::copyconstructors() const Token* tok = func.functionScope->bodyStart; for (const Token* const end = func.functionScope->bodyEnd; tok != end; tok = tok->next()) { if (Token::Match(tok, "delete %var%") || - (Token::Match(tok, "%name% ( %var%") && mSettings->library.getDeallocFuncInfo(tok))) { + (Token::Match(tok, "%name% ( %var%") && mSettings.library.getDeallocFuncInfo(tok))) { const Token *vartok = tok->str() == "delete" ? tok->next() : tok->tokAt(2); const Variable* var = vartok->variable(); if (var && var->isPointer() && var->scope() == scope && !var->isStatic()) @@ -580,7 +580,7 @@ void CheckClassImpl::copyconstructors() } for (tok = func.functionScope->bodyStart; tok != func.functionScope->bodyEnd; tok = tok->next()) { if ((tok->isCpp() && Token::Match(tok, "%var% = new")) || - (Token::Match(tok, "%var% = %name% (") && (mSettings->library.getAllocFuncInfo(tok->tokAt(2)) || mSettings->library.getReallocFuncInfo(tok->tokAt(2))))) { + (Token::Match(tok, "%var% = %name% (") && (mSettings.library.getAllocFuncInfo(tok->tokAt(2)) || mSettings.library.getReallocFuncInfo(tok->tokAt(2))))) { allocatedVars.erase(tok->varId()); } else if (Token::Match(tok, "%var% = %name% . %name% ;") && allocatedVars.find(tok->varId()) != allocatedVars.end()) { copiedVars.insert(tok); @@ -1059,7 +1059,7 @@ void CheckClassImpl::initializeVarList(const Function &func, std::listnext(); if (tok2->str() == "&") tok2 = tok2->next(); - if (isVariableChangedByFunctionCall(tok2, tok2->strAt(-1) == "&", tok2->varId(), *mSettings, nullptr)) + if (isVariableChangedByFunctionCall(tok2, tok2->strAt(-1) == "&", tok2->varId(), mSettings, nullptr)) assignVar(usage, tok2->varId()); } } @@ -1218,7 +1218,7 @@ void CheckClassImpl::operatorEqVarError(const Token *tok, const std::string &cla void CheckClassImpl::initializationListUsage() { - if (!mSettings->severity.isEnabled(Severity::performance)) + if (!mSettings.severity.isEnabled(Severity::performance)) return; logChecker("CheckClass::initializationListUsage"); // performance @@ -1279,7 +1279,7 @@ void CheckClassImpl::initializationListUsage() allowed = false; return ChildrenToVisit::done; } - if (var2->isLocal() && isVariableChanged(var2->nameToken(), previousBeforeAstLeftmostLeaf(tok), var2->declarationId(), /*globalvar*/ false, *mSettings)) { + if (var2->isLocal() && isVariableChanged(var2->nameToken(), previousBeforeAstLeftmostLeaf(tok), var2->declarationId(), /*globalvar*/ false, mSettings)) { allowed = false; return ChildrenToVisit::done; } @@ -1364,7 +1364,7 @@ static bool checkFunctionUsage(const Function *privfunc, const Scope* scope) void CheckClassImpl::privateFunctions() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("unusedPrivateFunction")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("unusedPrivateFunction")) return; logChecker("CheckClass::privateFunctions"); // style @@ -1447,7 +1447,7 @@ static const Scope* findFunctionOf(const Scope* scope) void CheckClassImpl::checkMemset() { logChecker("CheckClass::checkMemset"); - const bool printWarnings = mSettings->severity.isEnabled(Severity::warning); + const bool printWarnings = mSettings.severity.isEnabled(Severity::warning); for (const Scope *scope : mSymbolDatabase->functionScopes) { for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "memset|memcpy|memmove (")) { @@ -1505,7 +1505,7 @@ void CheckClassImpl::checkMemset() type = var->typeScope(); if (!type && !var->isPointer() && !Token::simpleMatch(var->typeStartToken(), "std :: array") && - mSettings->library.detectContainerOrIterator(var->typeStartToken())) { + mSettings.library.detectContainerOrIterator(var->typeStartToken())) { memsetError(tok, tok->str(), var->getTypeName(), {}, /*isContainer*/ true); } } @@ -1525,9 +1525,9 @@ void CheckClassImpl::checkMemset() checkMemsetType(scope, tok, type, false, {}); } } else if (tok->variable() && tok->variable()->isPointer() && tok->variable()->typeScope() && Token::Match(tok, "%var% = %name% (")) { - const Library::AllocFunc* alloc = mSettings->library.getAllocFuncInfo(tok->tokAt(2)); + const Library::AllocFunc* alloc = mSettings.library.getAllocFuncInfo(tok->tokAt(2)); if (!alloc) - alloc = mSettings->library.getReallocFuncInfo(tok->tokAt(2)); + alloc = mSettings.library.getReallocFuncInfo(tok->tokAt(2)); if (!alloc || alloc->bufferSize == Library::AllocFunc::BufferSize::none) continue; std::set parsedTypes; @@ -1547,7 +1547,7 @@ void CheckClassImpl::checkMemsetType(const Scope *start, const Token *tok, const return; parsedTypes.insert(type); - const bool printPortability = mSettings->severity.isEnabled(Severity::portability); + const bool printPortability = mSettings.severity.isEnabled(Severity::portability); // recursively check all parent classes for (const Type::BaseInfo & i : type->definedType->derivedFrom) { @@ -1588,7 +1588,7 @@ void CheckClassImpl::checkMemsetType(const Scope *start, const Token *tok, const } // check for std:: type - if (var.isStlType() && typeName != "std::array" && !mSettings->library.podtype(typeName)) { + if (var.isStlType() && typeName != "std::array" && !mSettings.library.podtype(typeName)) { if (allocation) mallocOnClassError(tok, tok->str(), type->classDef, "'" + typeName + "'"); else @@ -1663,7 +1663,7 @@ void CheckClassImpl::memsetErrorFloat(const Token *tok, const std::string &type) void CheckClassImpl::operatorEqRetRefThis() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("operatorEqRetRefThis")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("operatorEqRetRefThis")) return; logChecker("CheckClass::operatorEqRetRefThis"); // style @@ -1762,7 +1762,7 @@ void CheckClassImpl::checkReturnPtrThis(const Scope *scope, const Function *func } return; } - if (mSettings->library.isScopeNoReturn(last, nullptr)) { + if (mSettings.library.isScopeNoReturn(last, nullptr)) { // Typical wrong way to prohibit default assignment operator // by always throwing an exception or calling a noreturn function operatorEqShouldBeLeftUnimplementedError(func->token); @@ -1807,7 +1807,7 @@ void CheckClassImpl::operatorEqMissingReturnStatementError(const Token *tok, boo void CheckClassImpl::operatorEqToSelf() { - if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("operatorEqToSelf")) + if (!mSettings.severity.isEnabled(Severity::warning) && !mSettings.isPremiumEnabled("operatorEqToSelf")) return; logChecker("CheckClass::operatorEqToSelf"); // warning @@ -1867,13 +1867,13 @@ bool CheckClassImpl::hasAllocation(const Function *func, const Scope* scope, con end = func->functionScope->bodyEnd; for (const Token *tok = start; tok && (tok != end); tok = tok->next()) { if (((tok->isCpp() && Token::Match(tok, "%var% = new")) || - (Token::Match(tok, "%var% = %name% (") && mSettings->library.getAllocFuncInfo(tok->tokAt(2)))) && + (Token::Match(tok, "%var% = %name% (") && mSettings.library.getAllocFuncInfo(tok->tokAt(2)))) && isMemberVar(scope, tok)) return true; // check for deallocating memory const Token *var; - if (Token::Match(tok, "%name% ( %var%") && mSettings->library.getDeallocFuncInfo(tok)) + if (Token::Match(tok, "%name% ( %var%") && mSettings.library.getDeallocFuncInfo(tok)) var = tok->tokAt(2); else if (tok->isCpp() && Token::Match(tok, "delete [ ] %var%")) var = tok->tokAt(3); @@ -2006,7 +2006,7 @@ void CheckClassImpl::virtualDestructor() // * base class is deleted // unless inconclusive in which case: // * A class with any virtual functions should have a destructor that is either public and virtual or protected - const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive); + const bool printInconclusive = mSettings.certainty.isEnabled(Certainty::inconclusive); std::list inconclusiveErrors; @@ -2029,7 +2029,7 @@ void CheckClassImpl::virtualDestructor() } // Check if destructor is empty and non-empty .. - if (mSettings->standards.cpp <= Standards::CPP03) { + if (mSettings.standards.cpp <= Standards::CPP03) { // Find the destructor const Function *destructor = scope->getDestructor(); @@ -2136,7 +2136,7 @@ void CheckClassImpl::virtualDestructor() void CheckClassImpl::virtualDestructorError(const Token *tok, const std::string &Base, const std::string &Derived, bool inconclusive) { if (inconclusive) { - if (mSettings->severity.isEnabled(Severity::warning)) + if (mSettings.severity.isEnabled(Severity::warning)) reportError(tok, Severity::warning, "virtualDestructor", "$symbol:" + Base + "\nClass '$symbol' which has virtual members does not have a virtual destructor.", CWE404, Certainty::inconclusive); } else { reportError(tok, Severity::error, "virtualDestructor", @@ -2156,7 +2156,7 @@ void CheckClassImpl::virtualDestructorError(const Token *tok, const std::string void CheckClassImpl::thisSubtraction() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckClass::thisSubtraction"); // warning @@ -2185,9 +2185,9 @@ void CheckClassImpl::thisSubtractionError(const Token *tok) void CheckClassImpl::checkConst() { - if (!mSettings->severity.isEnabled(Severity::style) && - !mSettings->isPremiumEnabled("functionConst") && - !mSettings->isPremiumEnabled("functionStatic")) + if (!mSettings.severity.isEnabled(Severity::style) && + !mSettings.isPremiumEnabled("functionConst") && + !mSettings.isPremiumEnabled("functionStatic")) return; logChecker("CheckClass::checkConst"); // style,inconclusive @@ -2248,7 +2248,7 @@ void CheckClassImpl::checkConst() const std::string& opName = func.tokenDef->str(); if (opName.compare(8, 5, "const") != 0 && (endsWith(opName,'&') || endsWith(opName,'*'))) continue; - } else if (mSettings->library.isSmartPointer(func.retDef)) { + } else if (mSettings.library.isSmartPointer(func.retDef)) { // Don't warn if a std::shared_ptr etc is returned continue; } else { @@ -2271,7 +2271,7 @@ void CheckClassImpl::checkConst() const bool suggestStatic = memberAccessed != MemberAccess::MEMBER && !func.isOperator(); if ((returnsPtrOrRef || func.isConst() || func.hasLvalRefQualifier()) && !suggestStatic) continue; - if (!suggestStatic && !mSettings->certainty.isEnabled(Certainty::inconclusive)) + if (!suggestStatic && !mSettings.certainty.isEnabled(Certainty::inconclusive)) // functionConst is inconclusive. False positives: #3322. continue; if (suggestStatic && func.isConst()) { @@ -2535,7 +2535,7 @@ bool CheckClassImpl::checkConstFunc(const Scope *scope, const Function *func, Me return true; } - if (const Library::Function* fLib = mSettings->library.getFunction(funcTok)) + if (const Library::Function* fLib = mSettings.library.getFunction(funcTok)) if (fLib->isconst || fLib->ispure) return true; @@ -2696,12 +2696,12 @@ bool CheckClassImpl::checkConstFunc(const Scope *scope, const Function *func, Me } else if (var->smartPointerType() && var->smartPointerType()->classScope && isConstMemberFunc(var->smartPointerType()->classScope, end)) { // empty body - } else if (var->isSmartPointer() && Token::simpleMatch(tok1->next(), ".") && tok1->next()->originalName().empty() && mSettings->library.isFunctionConst(end)) { + } else if (var->isSmartPointer() && Token::simpleMatch(tok1->next(), ".") && tok1->next()->originalName().empty() && mSettings.library.isFunctionConst(end)) { // empty body } else if (hasOverloadedMemberAccess(end, var->typeScope())) { // empty body } else if (!var->typeScope() || (end->function() != func && !isConstMemberFunc(var->typeScope(), end))) { - if (!mSettings->library.isFunctionConst(end)) + if (!mSettings.library.isFunctionConst(end)) return false; } } @@ -2806,15 +2806,15 @@ namespace { // avoid one-definition-rule violation void CheckClassImpl::initializerListOrder() { - if (!mSettings->isPremiumEnabled("initializerList")) { - if (!mSettings->severity.isEnabled(Severity::style)) + if (!mSettings.isPremiumEnabled("initializerList")) { + if (!mSettings.severity.isEnabled(Severity::style)) return; // This check is not inconclusive. However it only determines if the initialization // order is incorrect. It does not determine if being out of order causes // a real error. Out of order is not necessarily an error but you can never // have an error if the list is in order so this enforces defensive programming. - if (!mSettings->certainty.isEnabled(Certainty::inconclusive)) + if (!mSettings.certainty.isEnabled(Certainty::inconclusive)) return; } @@ -2945,7 +2945,7 @@ void CheckClassImpl::selfInitializationError(const Token* tok, const std::string void CheckClassImpl::checkVirtualFunctionCallInConstructor() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckClass::checkVirtualFunctionCallInConstructor"); // warning std::map> virtualFunctionCallsMap; @@ -3012,8 +3012,8 @@ const std::list & CheckClassImpl::getVirtualFunctionCalls(const F tok->strAt(-1) == "(") { const Token * prev = tok->previous(); if (prev->previous() && - (mSettings->library.ignorefunction(tok->str()) - || mSettings->library.ignorefunction(prev->strAt(-1)))) + (mSettings.library.ignorefunction(tok->str()) + || mSettings.library.ignorefunction(prev->strAt(-1)))) continue; } @@ -3056,7 +3056,7 @@ void CheckClassImpl::virtualFunctionCallInConstructorError( const std::list & tokStack, const std::string &funcname) { - if (scopeFunction && !mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("virtualCallInConstructor")) + if (scopeFunction && !mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("virtualCallInConstructor")) return; const char * scopeFunctionTypeName = scopeFunction ? getFunctionTypeName(scopeFunction->type) : "constructor"; @@ -3116,7 +3116,7 @@ void CheckClassImpl::pureVirtualFunctionCallInConstructorError( void CheckClassImpl::checkDuplInheritedMembers() { - if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("duplInheritedMember")) + if (!mSettings.severity.isEnabled(Severity::warning) && !mSettings.isPremiumEnabled("duplInheritedMember")) return; logChecker("CheckClass::checkDuplInheritedMembers"); // warning @@ -3254,7 +3254,7 @@ void CheckClassImpl::checkCopyCtorAndEqOperator() { // TODO: This is disabled because of #8388 // The message must be clarified. How is the behaviour different? - if ((true) || !mSettings->severity.isEnabled(Severity::warning)) // NOLINT(readability-simplify-boolean-expr,readability-redundant-parentheses) + if ((true) || !mSettings.severity.isEnabled(Severity::warning)) // NOLINT(readability-simplify-boolean-expr,readability-redundant-parentheses) return; // logChecker @@ -3314,9 +3314,9 @@ void CheckClassImpl::copyCtorAndEqOperatorError(const Token *tok, const std::str void CheckClassImpl::checkOverride() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("missingOverride")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("missingOverride")) return; - if (mSettings->standards.cpp < Standards::CPP11) + if (mSettings.standards.cpp < Standards::CPP11) return; logChecker("CheckClass::checkMissingOverride"); // style,c++03 for (const Scope * classScope : mSymbolDatabase->classAndStructScopes) { @@ -3420,7 +3420,7 @@ static bool compareTokenRanges(const Token* start1, const Token* end1, const Tok void CheckClassImpl::checkUselessOverride() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("uselessOverride")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("uselessOverride")) return; logChecker("CheckClass::checkUselessOverride"); // style @@ -3501,7 +3501,7 @@ static const Variable* getSingleReturnVar(const Scope* scope) { void CheckClassImpl::checkReturnByReference() { - if (!mSettings->severity.isEnabled(Severity::performance) && !mSettings->isPremiumEnabled("returnByReference")) + if (!mSettings.severity.isEnabled(Severity::performance) && !mSettings.isPremiumEnabled("returnByReference")) return; logChecker("CheckClass::checkReturnByReference"); // performance @@ -3516,7 +3516,7 @@ void CheckClassImpl::checkReturnByReference() continue; if (func.functionPointerUsage) continue; - if (const Library::Container* container = mSettings->library.detectContainer(func.retDef)) + if (const Library::Container* container = mSettings.library.detectContainer(func.retDef)) if (container->view) continue; if (!func.isConst() && func.hasRvalRefQualifier()) @@ -3531,8 +3531,8 @@ void CheckClassImpl::checkReturnByReference() const bool isView = isContainer && var->valueType()->container->view; bool warn = isContainer && !isView; if (!warn && !isView) { - const std::size_t size = var->valueType()->getSizeOf(*mSettings, ValueType::Accuracy::LowerBound, ValueType::SizeOf::Pointer); - if (size > 2 * mSettings->platform.sizeof_pointer) + const std::size_t size = var->valueType()->getSizeOf(mSettings, ValueType::Accuracy::LowerBound, ValueType::SizeOf::Pointer); + if (size > 2 * mSettings.platform.sizeof_pointer) warn = true; } if (warn) @@ -3551,7 +3551,7 @@ void CheckClassImpl::returnByReferenceError(const Function* func, const Variable void CheckClassImpl::checkThisUseAfterFree() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckClass::checkThisUseAfterFree"); // warning @@ -3561,7 +3561,7 @@ void CheckClassImpl::checkThisUseAfterFree() for (const Variable &var : classScope->varlist) { // Find possible "self pointer".. pointer/smartpointer member variable of "self" type. if (var.valueType() && var.valueType()->smartPointerType != classScope->definedType && var.valueType()->typeScope != classScope) { - const ValueType valueType = ValueType::parseDecl(var.typeStartToken(), *mSettings); + const ValueType valueType = ValueType::parseDecl(var.typeStartToken(), mSettings); if (valueType.smartPointerType != classScope->definedType) continue; } @@ -3651,7 +3651,7 @@ void CheckClassImpl::thisUseAfterFree(const Token *self, const Token *free, cons void CheckClassImpl::checkUnsafeClassRefMember() { - if (!mSettings->safeChecks.classes || !mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.safeChecks.classes || !mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckClass::checkUnsafeClassRefMember"); // warning,safeChecks for (const Scope * classScope : mSymbolDatabase->classAndStructScopes) { @@ -3833,7 +3833,7 @@ bool CheckClass::analyseWholeProgram(const CTU::FileInfo &ctu, const std::list &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { return "Check the code for each class.\n" @@ -100,7 +100,7 @@ class CPPCHECKLIB CheckClass : public Check { class CPPCHECKLIB CheckClassImpl : public CheckImpl { public: /** This constructor is used when running checks. */ - CheckClassImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger); + CheckClassImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger); /** @brief Set of the STL types whose operator[] is not const */ static const std::set stl_containers_not_const; diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 163b05cc445..365a677b5cb 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -91,7 +91,7 @@ bool CheckConditionImpl::isAliased(const std::set &vars) const void CheckConditionImpl::assignIf() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("assignIfError")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("assignIfError")) return; logChecker("CheckCondition::assignIf"); // style @@ -204,7 +204,7 @@ bool CheckConditionImpl::assignIfParseScope(const Token * const assignTok, // is variable changed in loop? const Token *bodyStart = tok2->linkAt(1)->next(); const Token *bodyEnd = bodyStart ? bodyStart->link() : nullptr; - if (!bodyEnd || bodyEnd->str() != "}" || isVariableChanged(bodyStart, bodyEnd, varid, !islocal, *mSettings)) + if (!bodyEnd || bodyEnd->str() != "}" || isVariableChanged(bodyStart, bodyEnd, varid, !islocal, mSettings)) continue; } @@ -310,7 +310,7 @@ static bool isOperandExpanded(const Token *tok) void CheckConditionImpl::checkBadBitmaskCheck() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("badBitmaskCheck")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("badBitmaskCheck")) return; logChecker("CheckCondition::checkBadBitmaskCheck"); // style @@ -358,7 +358,7 @@ void CheckConditionImpl::badBitmaskCheckError(const Token *tok, bool isNoOp) void CheckConditionImpl::comparison() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("comparisonError")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("comparisonError")) return; logChecker("CheckCondition::comparison"); // style @@ -441,7 +441,7 @@ bool CheckConditionImpl::isOverlappingCond(const Token * const cond1, const Toke return false; // same expressions - if (isSameExpression(true, cond1, cond2, *mSettings, pure, false)) + if (isSameExpression(true, cond1, cond2, mSettings, pure, false)) return true; // bitwise overlap for example 'x&7' and 'x==1' @@ -464,7 +464,7 @@ bool CheckConditionImpl::isOverlappingCond(const Token * const cond1, const Toke if (!num2->isNumber() || MathLib::isNegative(num2->str())) return false; - if (!isSameExpression(true, expr1, expr2, *mSettings, pure, false)) + if (!isSameExpression(true, expr1, expr2, mSettings, pure, false)) return false; const MathLib::bigint value1 = MathLib::toBigNumber(num1); @@ -478,7 +478,7 @@ bool CheckConditionImpl::isOverlappingCond(const Token * const cond1, const Toke void CheckConditionImpl::duplicateCondition() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("duplicateCondition")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("duplicateCondition")) return; logChecker("CheckCondition::duplicateCondition"); // style @@ -509,8 +509,8 @@ void CheckConditionImpl::duplicateCondition() continue; ErrorPath errorPath; - if (!findExpressionChanged(cond1, scope.classDef->next(), cond2, *mSettings) && - isSameExpression(true, cond1, cond2, *mSettings, true, true, &errorPath)) + if (!findExpressionChanged(cond1, scope.classDef->next(), cond2, mSettings) && + isSameExpression(true, cond1, cond2, mSettings, true, true, &errorPath)) duplicateConditionError(cond1, cond2, std::move(errorPath)); } } @@ -529,7 +529,7 @@ void CheckConditionImpl::duplicateConditionError(const Token *tok1, const Token void CheckConditionImpl::multiCondition() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("multiCondition")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("multiCondition")) return; logChecker("CheckCondition::multiCondition"); // style @@ -559,11 +559,11 @@ void CheckConditionImpl::multiCondition() if (tok2->astOperand2()) { ErrorPath errorPath; if (isOverlappingCond(cond1, tok2->astOperand2(), true) && - !findExpressionChanged(cond1, cond1, tok2->astOperand2(), *mSettings)) + !findExpressionChanged(cond1, cond1, tok2->astOperand2(), mSettings)) overlappingElseIfConditionError(tok2->astOperand2(), cond1->linenr()); else if (isOppositeCond( - true, cond1, tok2->astOperand2(), *mSettings, true, true, &errorPath) && - !findExpressionChanged(cond1, cond1, tok2->astOperand2(), *mSettings)) + true, cond1, tok2->astOperand2(), mSettings, true, true, &errorPath) && + !findExpressionChanged(cond1, cond1, tok2->astOperand2(), mSettings)) oppositeElseIfConditionError(cond1, tok2->astOperand2(), std::move(errorPath)); } } @@ -631,9 +631,9 @@ static bool isNestedInLambda(const Scope* inner, const Scope* outer) void CheckConditionImpl::multiCondition2() { - if (!mSettings->severity.isEnabled(Severity::warning) && - !mSettings->isPremiumEnabled("identicalConditionAfterEarlyExit") && - !mSettings->isPremiumEnabled("identicalInnerCondition")) + if (!mSettings.severity.isEnabled(Severity::warning) && + !mSettings.isPremiumEnabled("identicalConditionAfterEarlyExit") && + !mSettings.isPremiumEnabled("identicalInnerCondition")) return; logChecker("CheckCondition::multiCondition2"); // warning @@ -668,7 +668,7 @@ void CheckConditionImpl::multiCondition2() [&](const Token *cond) { if (Token::Match(cond, "%name% (")) { functionCall = true; - nonConstFunctionCall = isNonConstFunctionCall(cond, mSettings->library); + nonConstFunctionCall = isNonConstFunctionCall(cond, mSettings.library); if (nonConstFunctionCall) return ChildrenToVisit::done; } @@ -725,13 +725,13 @@ void CheckConditionImpl::multiCondition2() for (; tok && tok != endToken; tok = tok->next()) { if (isNestedInLambda(tok->scope(), cond1->scope())) continue; - if (isExpressionChangedAt(cond1, tok, 0, false, *mSettings)) + if (isExpressionChangedAt(cond1, tok, 0, false, mSettings)) break; if (Token::Match(tok, "if|return")) { const Token * condStartToken = tok->str() == "if" ? tok->next() : tok; const Token * condEndToken = tok->str() == "if" ? condStartToken->link() : Token::findsimplematch(condStartToken, ";"); // Does condition modify tracked variables? - if (findExpressionChanged(cond1, condStartToken, condEndToken, *mSettings)) + if (findExpressionChanged(cond1, condStartToken, condEndToken, mSettings)) break; // Condition.. @@ -745,14 +745,14 @@ void CheckConditionImpl::multiCondition2() if (!firstCondition) return ChildrenToVisit::none; if (firstCondition->str() == "&&") { - if (!isOppositeCond(false, firstCondition, cond2, *mSettings, true, true)) + if (!isOppositeCond(false, firstCondition, cond2, mSettings, true, true)) return ChildrenToVisit::op1_and_op2; } if (!firstCondition->hasKnownIntValue()) { - if (!isReturnVar && isOppositeCond(false, firstCondition, cond2, *mSettings, true, true, &errorPath)) { + if (!isReturnVar && isOppositeCond(false, firstCondition, cond2, mSettings, true, true, &errorPath)) { if (!isAliased(vars)) oppositeInnerConditionError(firstCondition, cond2, errorPath); - } else if (!isReturnVar && isSameExpression(true, firstCondition, cond2, *mSettings, true, true, &errorPath)) { + } else if (!isReturnVar && isSameExpression(true, firstCondition, cond2, mSettings, true, true, &errorPath)) { identicalInnerConditionError(firstCondition, cond2, errorPath); } else if (!isReturnVar && isOverlappingCond(cond2, firstCondition, true)) { overlappingInnerConditionError(firstCondition, cond2, errorPath); @@ -766,7 +766,7 @@ void CheckConditionImpl::multiCondition2() return ChildrenToVisit::op1_and_op2; if ((!cond1->hasKnownIntValue() || !secondCondition->hasKnownIntValue()) && - isSameExpression(true, cond1, secondCondition, *mSettings, true, true, &errorPath)) { + isSameExpression(true, cond1, secondCondition, mSettings, true, true, &errorPath)) { if (!isAliased(vars) && !mTokenizer->hasIfdef(cond1, secondCondition)) { identicalConditionAfterEarlyExitError(cond1, secondCondition, errorPath); return ChildrenToVisit::done; @@ -777,10 +777,10 @@ void CheckConditionImpl::multiCondition2() } } if (Token::Match(tok, "%name% (") && - isVariablesChanged(tok, tok->linkAt(1), 0, varsInCond, *mSettings)) { + isVariablesChanged(tok, tok->linkAt(1), 0, varsInCond, mSettings)) { break; } - if (Token::Match(tok, "%type% (") && nonlocal && isNonConstFunctionCall(tok, mSettings->library)) // non const function call -> bailout if there are nonlocal variables + if (Token::Match(tok, "%type% (") && nonlocal && isNonConstFunctionCall(tok, mSettings.library)) // non const function call -> bailout if there are nonlocal variables break; if (Token::Match(tok, "case|break|continue|return|throw") && tok->scope() == endToken->scope()) break; @@ -806,7 +806,7 @@ void CheckConditionImpl::multiCondition2() break; } const bool changed = std::any_of(vars.cbegin(), vars.cend(), [&](int varid) { - return isVariableChanged(tok1, tok2, varid, nonlocal, *mSettings); + return isVariableChanged(tok1, tok2, varid, nonlocal, mSettings); }); if (changed) break; @@ -1158,11 +1158,11 @@ static bool isIfConstexpr(const Token* tok) { void CheckConditionImpl::checkIncorrectLogicOperator() { - const bool printStyle = mSettings->severity.isEnabled(Severity::style); - const bool printWarning = mSettings->severity.isEnabled(Severity::warning); - if (!printWarning && !printStyle && !mSettings->isPremiumEnabled("incorrectLogicOperator")) + const bool printStyle = mSettings.severity.isEnabled(Severity::style); + const bool printWarning = mSettings.severity.isEnabled(Severity::warning); + if (!printWarning && !printStyle && !mSettings.isPremiumEnabled("incorrectLogicOperator")) return; - const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive); + const bool printInconclusive = mSettings.certainty.isEnabled(Certainty::inconclusive); logChecker("CheckCondition::checkIncorrectLogicOperator"); // style,warning @@ -1182,7 +1182,7 @@ void CheckConditionImpl::checkIncorrectLogicOperator() ((tok->str() == "||" && tok->astOperand2()->str() == "&&") || (tok->str() == "&&" && tok->astOperand2()->str() == "||"))) { const Token* tok2 = tok->astOperand2()->astOperand1(); - if (isOppositeCond(true, tok->astOperand1(), tok2, *mSettings, true, false)) { + if (isOppositeCond(true, tok->astOperand1(), tok2, mSettings, true, false)) { std::string expr1(tok->astOperand1()->expressionString()); std::string expr2(tok->astOperand2()->astOperand1()->expressionString()); std::string expr3(tok->astOperand2()->astOperand2()->expressionString()); @@ -1214,7 +1214,7 @@ void CheckConditionImpl::checkIncorrectLogicOperator() redundantConditionError(tok, msg, false); continue; } - if (isSameExpression(false, tok->astOperand1(), tok2, *mSettings, true, true)) { + if (isSameExpression(false, tok->astOperand1(), tok2, mSettings, true, true)) { std::string expr1(tok->astOperand1()->expressionString()); std::string expr2(tok->astOperand2()->astOperand1()->expressionString()); std::string expr3(tok->astOperand2()->astOperand2()->expressionString()); @@ -1279,7 +1279,7 @@ void CheckConditionImpl::checkIncorrectLogicOperator() // Opposite comparisons around || or && => always true or always false const bool isLogicalOr(tok->str() == "||"); - if (!isfloat && isOppositeCond(isLogicalOr, tok->astOperand1(), tok->astOperand2(), *mSettings, true, true, &errorPath)) { + if (!isfloat && isOppositeCond(isLogicalOr, tok->astOperand1(), tok->astOperand2(), mSettings, true, true, &errorPath)) { if (!isIfConstexpr(tok)) { const bool alwaysTrue(isLogicalOr); incorrectLogicOperatorError(tok, conditionString(tok), alwaysTrue, inconclusive, std::move(errorPath)); @@ -1290,9 +1290,9 @@ void CheckConditionImpl::checkIncorrectLogicOperator() if (!parseable) continue; - if (isSameExpression(true, comp1, comp2, *mSettings, true, true)) + if (isSameExpression(true, comp1, comp2, mSettings, true, true)) continue; // same expressions => only report that there are same expressions - if (!isSameExpression(true, expr1, expr2, *mSettings, true, true)) + if (!isSameExpression(true, expr1, expr2, mSettings, true, true)) continue; @@ -1396,7 +1396,7 @@ void CheckConditionImpl::redundantConditionError(const Token *tok, const std::st //----------------------------------------------------------------------------- void CheckConditionImpl::checkModuloAlwaysTrueFalse() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckCondition::checkModuloAlwaysTrueFalse"); // warning @@ -1452,7 +1452,7 @@ static int countPar(const Token *tok1, const Token *tok2) //--------------------------------------------------------------------------- void CheckConditionImpl::clarifyCondition() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("clarifyCondition")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("clarifyCondition")) return; logChecker("CheckCondition::clarifyCondition"); // style @@ -1516,11 +1516,11 @@ void CheckConditionImpl::clarifyConditionError(const Token *tok, bool assign, bo void CheckConditionImpl::alwaysTrueFalse() { - const bool pedantic = mSettings->isPremiumEnabled("alwaysTrue") || - mSettings->isPremiumEnabled("alwaysFalse") || - mSettings->isPremiumEnabled("knownConditionTrueFalse"); + const bool pedantic = mSettings.isPremiumEnabled("alwaysTrue") || + mSettings.isPremiumEnabled("alwaysFalse") || + mSettings.isPremiumEnabled("knownConditionTrueFalse"); - if (!pedantic && !mSettings->severity.isEnabled(Severity::style)) + if (!pedantic && !mSettings.severity.isEnabled(Severity::style)) return; logChecker("CheckCondition::alwaysTrueFalse"); // style @@ -1569,7 +1569,7 @@ void CheckConditionImpl::alwaysTrueFalse() continue; if (condition->isConstexpr()) continue; - if (!isUsedAsBool(tok, *mSettings)) + if (!isUsedAsBool(tok, mSettings)) continue; if (Token::simpleMatch(condition, "return") && Token::Match(tok, "%assign%")) continue; @@ -1598,7 +1598,7 @@ void CheckConditionImpl::alwaysTrueFalse() isSameExpression(true, tok->astOperand1(), tok->astOperand2(), - *mSettings, + mSettings, true, true)) continue; @@ -1702,7 +1702,7 @@ void CheckConditionImpl::checkInvalidTestForOverflow() // x + y < x -> y < 0 - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckCondition::checkInvalidTestForOverflow"); // warning @@ -1736,7 +1736,7 @@ void CheckConditionImpl::checkInvalidTestForOverflow() if (!isSameExpression(true, expr, lhs->astSibling(), - *mSettings, + mSettings, true, false)) continue; @@ -1792,7 +1792,7 @@ void CheckConditionImpl::invalidTestForOverflow(const Token* tok, const ValueTyp void CheckConditionImpl::checkPointerAdditionResultNotNull() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckCondition::checkPointerAdditionResultNotNull"); // warning @@ -1839,7 +1839,7 @@ void CheckConditionImpl::pointerAdditionResultNotNullError(const Token *tok, con void CheckConditionImpl::checkDuplicateConditionalAssign() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("duplicateConditionalAssign")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("duplicateConditionalAssign")) return; logChecker("CheckCondition::checkDuplicateConditionalAssign"); // style @@ -1883,10 +1883,10 @@ void CheckConditionImpl::checkDuplicateConditionalAssign() isRedundant = (isNegation && val == 0) || (!isNegation && val == 1); } else { // comparison if (!isSameExpression( - true, condTok->astOperand1(), assignTok->astOperand1(), *mSettings, true, true)) + true, condTok->astOperand1(), assignTok->astOperand1(), mSettings, true, true)) continue; if (!isSameExpression( - true, condTok->astOperand2(), assignTok->astOperand2(), *mSettings, true, true)) + true, condTok->astOperand2(), assignTok->astOperand2(), mSettings, true, true)) continue; } duplicateConditionalAssignError(condTok, assignTok, isRedundant); @@ -1918,7 +1918,7 @@ void CheckConditionImpl::duplicateConditionalAssignError(const Token *condTok, c void CheckConditionImpl::checkAssignmentInCondition() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("assignmentInCondition")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("assignmentInCondition")) return; logChecker("CheckCondition::checkAssignmentInCondition"); // style @@ -1965,10 +1965,10 @@ void CheckConditionImpl::assignmentInCondition(const Token *eq) void CheckConditionImpl::checkCompareValueOutOfTypeRange() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("compareValueOutOfTypeRangeError")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("compareValueOutOfTypeRangeError")) return; - if (mSettings->platform.type == Platform::Type::Unspecified) + if (mSettings.platform.type == Platform::Type::Unspecified) return; logChecker("CheckCondition::checkCompareValueOutOfTypeRange"); // style,platform @@ -1994,19 +1994,19 @@ void CheckConditionImpl::checkCompareValueOutOfTypeRange() bits = 1; break; case ValueType::Type::CHAR: - bits = mSettings->platform.char_bit; + bits = mSettings.platform.char_bit; break; case ValueType::Type::SHORT: - bits = mSettings->platform.short_bit; + bits = mSettings.platform.short_bit; break; case ValueType::Type::INT: - bits = mSettings->platform.int_bit; + bits = mSettings.platform.int_bit; break; case ValueType::Type::LONG: - bits = mSettings->platform.long_bit; + bits = mSettings.platform.long_bit; break; case ValueType::Type::LONGLONG: - bits = mSettings->platform.long_long_bit; + bits = mSettings.platform.long_long_bit; break; default: break; @@ -2019,7 +2019,7 @@ void CheckConditionImpl::checkCompareValueOutOfTypeRange() long long typeMaxValue; if (typeTok->valueType()->sign != ValueType::Sign::SIGNED) typeMaxValue = unsignedTypeMaxValue; - else if (bits >= mSettings->platform.int_bit && (!valueTok->valueType() || valueTok->valueType()->sign != ValueType::Sign::SIGNED)) + else if (bits >= mSettings.platform.int_bit && (!valueTok->valueType() || valueTok->valueType()->sign != ValueType::Sign::SIGNED)) typeMaxValue = unsignedTypeMaxValue; else typeMaxValue = unsignedTypeMaxValue / 2; @@ -2097,7 +2097,7 @@ void CheckConditionImpl::compareValueOutOfTypeRangeError(const Token *comparison void CheckCondition::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckConditionImpl checkCondition(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckConditionImpl checkCondition(&tokenizer, tokenizer.getSettings(), errorLogger); checkCondition.multiCondition(); checkCondition.clarifyCondition(); // not simplified because ifAssign checkCondition.multiCondition2(); @@ -2115,7 +2115,7 @@ void CheckCondition::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLog checkCondition.alwaysTrueFalse(); } -void CheckCondition::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckCondition::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckConditionImpl c(nullptr, settings, errorLogger); diff --git a/lib/checkcondition.h b/lib/checkcondition.h index be06dfbbfd2..06ed12695bc 100644 --- a/lib/checkcondition.h +++ b/lib/checkcondition.h @@ -56,7 +56,7 @@ class CPPCHECKLIB CheckCondition : public Check { private: void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { return "Match conditions with assignments and other conditions:\n" @@ -81,7 +81,7 @@ class CPPCHECKLIB CheckCondition : public Check { class CPPCHECKLIB CheckConditionImpl : public CheckImpl { public: /** This constructor is used when running checks. */ - CheckConditionImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckConditionImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** mismatching assignment / comparison */ diff --git a/lib/checkexceptionsafety.cpp b/lib/checkexceptionsafety.cpp index 463e47bea1c..b0c510ed80a 100644 --- a/lib/checkexceptionsafety.cpp +++ b/lib/checkexceptionsafety.cpp @@ -42,7 +42,7 @@ static const CWE CWE480(480U); // Use of Incorrect Operator void CheckExceptionSafetyImpl::destructors() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckExceptionSafety::destructors"); // warning @@ -90,12 +90,12 @@ void CheckExceptionSafetyImpl::destructorsError(const Token * const tok, const s void CheckExceptionSafetyImpl::deallocThrow() { - if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("exceptDeallocThrow")) + if (!mSettings.severity.isEnabled(Severity::warning) && !mSettings.isPremiumEnabled("exceptDeallocThrow")) return; logChecker("CheckExceptionSafety::deallocThrow"); // warning - const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive); + const bool printInconclusive = mSettings.certainty.isEnabled(Certainty::inconclusive); const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase(); // Deallocate a global/member pointer and then throw exception @@ -165,7 +165,7 @@ void CheckExceptionSafetyImpl::deallocThrowError(const Token * const tok, const //--------------------------------------------------------------------------- void CheckExceptionSafetyImpl::checkRethrowCopy() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("exceptRethrowCopy")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("exceptRethrowCopy")) return; logChecker("CheckExceptionSafety::checkRethrowCopy"); // style @@ -209,7 +209,7 @@ void CheckExceptionSafetyImpl::rethrowCopyError(const Token * const tok, const s //--------------------------------------------------------------------------- void CheckExceptionSafetyImpl::checkCatchExceptionByValue() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("catchExceptionByValue")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("catchExceptionByValue")) return; logChecker("CheckExceptionSafety::checkCatchExceptionByValue"); // style @@ -298,7 +298,7 @@ void CheckExceptionSafetyImpl::nothrowThrows() function->isAttributeNothrow()) { // __attribute__((nothrow)) or __declspec(nothrow) functions isNoExcept = true; } - else if (mSettings->library.isentrypoint(function->name())) { + else if (mSettings.library.isentrypoint(function->name())) { isEntryPoint = true; } if (!isNoExcept && !isEntryPoint) @@ -328,8 +328,8 @@ void CheckExceptionSafetyImpl::entryPointThrowError(const Token * const tok) //-------------------------------------------------------------------------- void CheckExceptionSafetyImpl::unhandledExceptionSpecification() { - if ((!mSettings->severity.isEnabled(Severity::style) || !mSettings->certainty.isEnabled(Certainty::inconclusive)) && - !mSettings->isPremiumEnabled("unhandledExceptionSpecification")) + if ((!mSettings.severity.isEnabled(Severity::style) || !mSettings.certainty.isEnabled(Certainty::inconclusive)) && + !mSettings.isPremiumEnabled("unhandledExceptionSpecification")) return; logChecker("CheckExceptionSafety::unhandledExceptionSpecification"); // style,inconclusive @@ -338,7 +338,7 @@ void CheckExceptionSafetyImpl::unhandledExceptionSpecification() for (const Scope * scope : symbolDatabase->functionScopes) { // only check functions without exception specification - if (scope->function && !scope->function->isThrow() && !mSettings->library.isentrypoint(scope->className)) { + if (scope->function && !scope->function->isThrow() && !mSettings.library.isentrypoint(scope->className)) { for (const Token *tok = scope->function->functionScope->bodyStart->next(); tok != scope->function->functionScope->bodyEnd; tok = tok->next()) { if (tok->str() == "try") @@ -414,7 +414,7 @@ void CheckExceptionSafety::runChecks(const Tokenizer &tokenizer, ErrorLogger *er if (tokenizer.isC()) return; - CheckExceptionSafetyImpl checkExceptionSafety(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckExceptionSafetyImpl checkExceptionSafety(&tokenizer, tokenizer.getSettings(), errorLogger); checkExceptionSafety.destructors(); checkExceptionSafety.deallocThrow(); checkExceptionSafety.checkRethrowCopy(); @@ -424,7 +424,7 @@ void CheckExceptionSafety::runChecks(const Tokenizer &tokenizer, ErrorLogger *er checkExceptionSafety.rethrowNoCurrentException(); } -void CheckExceptionSafety::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckExceptionSafety::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckExceptionSafetyImpl c(nullptr, settings, errorLogger); c.destructorsError(nullptr, "Class"); diff --git a/lib/checkexceptionsafety.h b/lib/checkexceptionsafety.h index bd44a649b1e..d452dac2cf8 100644 --- a/lib/checkexceptionsafety.h +++ b/lib/checkexceptionsafety.h @@ -53,7 +53,7 @@ class CPPCHECKLIB CheckExceptionSafety : public Check { void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; /** Generate all possible errors (for --errorlist) */ - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; /** wiki formatted description of the class (for --doc) */ std::string classInfo() const override { @@ -71,7 +71,7 @@ class CPPCHECKLIB CheckExceptionSafety : public Check { class CPPCHECKLIB CheckExceptionSafetyImpl : public CheckImpl { public: /** This constructor is used when running checks. */ - CheckExceptionSafetyImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckExceptionSafetyImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** Don't throw exceptions in destructors */ diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index 47a3828de31..db50846b262 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -54,7 +54,7 @@ static const CWE CWE688(688U); // Function Call With Incorrect Variable or Refe void CheckFunctionsImpl::checkProhibitedFunctions() { - const bool checkAlloca = mSettings->severity.isEnabled(Severity::warning) && ((mTokenizer->isC() && mSettings->standards.c >= Standards::C99) || mSettings->standards.cpp >= Standards::CPP11); + const bool checkAlloca = mSettings.severity.isEnabled(Severity::warning) && ((mTokenizer->isC() && mSettings.standards.c >= Standards::C99) || mSettings.standards.cpp >= Standards::CPP11); logChecker("CheckFunctions::checkProhibitedFunctions"); @@ -66,7 +66,7 @@ void CheckFunctionsImpl::checkProhibitedFunctions() // alloca() is special as it depends on the code being C or C++, so it is not in Library if (checkAlloca && Token::simpleMatch(tok, "alloca (") && (!tok->function() || tok->function()->nestedIn->type == ScopeType::eGlobal)) { if (tok->isC()) { - if (mSettings->standards.c > Standards::C89) + if (mSettings.standards.c > Standards::C89) reportError(tok, Severity::warning, "allocaCalled", "$symbol:alloca\n" "Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead.\n" @@ -84,10 +84,10 @@ void CheckFunctionsImpl::checkProhibitedFunctions() if (tok->function() && tok->function()->hasBody()) continue; - const Library::WarnInfo* wi = mSettings->library.getWarnInfo(tok); + const Library::WarnInfo* wi = mSettings.library.getWarnInfo(tok); if (wi) { - if (mSettings->severity.isEnabled(wi->severity) && ((tok->isC() && mSettings->standards.c >= wi->standards.c) || (tok->isCpp() && mSettings->standards.cpp >= wi->standards.cpp))) { - const std::string daca = mSettings->daca ? "prohibited" : ""; + if (mSettings.severity.isEnabled(wi->severity) && ((tok->isC() && mSettings.standards.c >= wi->standards.c) || (tok->isCpp() && mSettings.standards.cpp >= wi->standards.cpp))) { + const std::string daca = mSettings.daca ? "prohibited" : ""; const std::string prefix = daca + tok->str(); functionCalledError(tok, wi->severity, prefix, wi->message); } @@ -120,24 +120,24 @@ void CheckFunctionsImpl::invalidFunctionUsage() const Token * const argtok = arguments[argnr-1]; // check ... - const ValueFlow::Value *invalidValue = argtok->getInvalidValue(functionToken,argnr,*mSettings); + const ValueFlow::Value *invalidValue = argtok->getInvalidValue(functionToken,argnr,mSettings); if (invalidValue) { - invalidFunctionArgError(argtok, functionToken->next()->astOperand1()->expressionString(), argnr, invalidValue, mSettings->library.validarg(functionToken, argnr)); + invalidFunctionArgError(argtok, functionToken->next()->astOperand1()->expressionString(), argnr, invalidValue, mSettings.library.validarg(functionToken, argnr)); } if (astIsBool(argtok)) { // check - if (mSettings->library.isboolargbad(functionToken, argnr)) + if (mSettings.library.isboolargbad(functionToken, argnr)) invalidFunctionArgBoolError(argtok, functionToken->str(), argnr); // Are the values 0 and 1 valid? - else if (!mSettings->library.isIntArgValid(functionToken, argnr, 0, *mSettings)) - invalidFunctionArgError(argtok, functionToken->str(), argnr, nullptr, mSettings->library.validarg(functionToken, argnr)); - else if (!mSettings->library.isIntArgValid(functionToken, argnr, 1, *mSettings)) - invalidFunctionArgError(argtok, functionToken->str(), argnr, nullptr, mSettings->library.validarg(functionToken, argnr)); + else if (!mSettings.library.isIntArgValid(functionToken, argnr, 0, mSettings)) + invalidFunctionArgError(argtok, functionToken->str(), argnr, nullptr, mSettings.library.validarg(functionToken, argnr)); + else if (!mSettings.library.isIntArgValid(functionToken, argnr, 1, mSettings)) + invalidFunctionArgError(argtok, functionToken->str(), argnr, nullptr, mSettings.library.validarg(functionToken, argnr)); } // check - if (mSettings->library.isargstrz(functionToken, argnr)) { + if (mSettings.library.isargstrz(functionToken, argnr)) { if (Token::Match(argtok, "& %var% !![") && argtok->next() && argtok->next()->valueType()) { const ValueType * valueType = argtok->next()->valueType(); const Variable * variable = argtok->next()->variable(); @@ -153,7 +153,7 @@ void CheckFunctionsImpl::invalidFunctionUsage() // Is non-null terminated local variable of type char (e.g. char buf[] = {'x'};) ? if (variable && variable->isLocal() && valueType && (valueType->type == ValueType::Type::CHAR || valueType->type == ValueType::Type::WCHAR_T) - && !isVariablesChanged(variable->declEndToken(), functionToken, valueType->pointer, { variable }, *mSettings)) { + && !isVariablesChanged(variable->declEndToken(), functionToken, valueType->pointer, { variable }, mSettings)) { const Token* varTok = variable->declEndToken(); MathLib::bigint count = -1; // Find out explicitly set count, e.g.: char buf[3] = {...}. Variable 'count' is set to 3 then. if (varTok && Token::simpleMatch(varTok->astOperand1(), "[")) @@ -183,7 +183,7 @@ void CheckFunctionsImpl::invalidFunctionUsage() invalidFunctionArgStrError(argtok, functionToken->str(), argnr); } } else if (count > -1 && Token::Match(varTok, "= %str%")) { - const Token* strTok = varTok->getValueTokenMinStrSize(*mSettings); + const Token* strTok = varTok->getValueTokenMinStrSize(mSettings); if (strTok) { const int strSize = Token::getStrArraySize(strTok); if (strSize > count && strTok->str().find('\0') == std::string::npos) @@ -247,9 +247,9 @@ void CheckFunctionsImpl::invalidFunctionArgStrError(const Token *tok, const std: //--------------------------------------------------------------------------- void CheckFunctionsImpl::checkIgnoredReturnValue() { - if (!mSettings->severity.isEnabled(Severity::warning) && - !mSettings->severity.isEnabled(Severity::style) && - !mSettings->isPremiumEnabled("ignoredReturnValue")) + if (!mSettings.severity.isEnabled(Severity::warning) && + !mSettings.severity.isEnabled(Severity::style) && + !mSettings.isPremiumEnabled("ignoredReturnValue")) return; logChecker("CheckFunctions::checkIgnoredReturnValue"); // style,warning @@ -282,13 +282,13 @@ void CheckFunctionsImpl::checkIgnoredReturnValue() if ((!tok->function() || !Token::Match(tok->function()->retDef, "void %name%")) && tok->next()->astOperand1()) { - const Library::UseRetValType retvalTy = mSettings->library.getUseRetValType(tok); + const Library::UseRetValType retvalTy = mSettings.library.getUseRetValType(tok); const bool warn = (tok->function() && (tok->function()->isAttributeNodiscard() || tok->function()->isAttributePure() || tok->function()->isAttributeConst())) || // avoid duplicate warnings for resource-allocating functions - (retvalTy == Library::UseRetValType::DEFAULT && mSettings->library.getAllocFuncInfo(tok) == nullptr); - if (mSettings->severity.isEnabled(Severity::warning) && warn) + (retvalTy == Library::UseRetValType::DEFAULT && mSettings.library.getAllocFuncInfo(tok) == nullptr); + if (mSettings.severity.isEnabled(Severity::warning) && warn) ignoredReturnValueError(tok, tok->next()->astOperand1()->expressionString()); - else if (mSettings->severity.isEnabled(Severity::style) && + else if (mSettings.severity.isEnabled(Severity::style) && retvalTy == Library::UseRetValType::ERROR_CODE) ignoredReturnErrorCode(tok, tok->next()->astOperand1()->expressionString()); } @@ -321,7 +321,7 @@ void CheckFunctionsImpl::checkMissingReturn() const Function *function = scope->function; if (!function || !function->hasBody()) continue; - if (function->name() == "main" && !(mTokenizer->isC() && mSettings->standards.c < Standards::C99)) + if (function->name() == "main" && !(mTokenizer->isC() && mSettings.standards.c < Standards::C99)) continue; if (function->type != FunctionType::eFunction && function->type != FunctionType::eOperatorEqual) continue; @@ -329,7 +329,7 @@ void CheckFunctionsImpl::checkMissingReturn() continue; if (Function::returnsVoid(function, true)) continue; - const Token *errorToken = checkMissingReturnScope(scope->bodyEnd, mSettings->library); + const Token *errorToken = checkMissingReturnScope(scope->bodyEnd, mSettings.library); if (errorToken) missingReturnError(errorToken); } @@ -441,10 +441,10 @@ void CheckFunctionsImpl::missingReturnError(const Token* tok) //--------------------------------------------------------------------------- void CheckFunctionsImpl::checkMathFunctions() { - const bool styleC99 = mSettings->severity.isEnabled(Severity::style) && ((mTokenizer->isC() && mSettings->standards.c != Standards::C89) || (mTokenizer->isCPP() && mSettings->standards.cpp != Standards::CPP03)); - const bool printWarnings = mSettings->severity.isEnabled(Severity::warning); + const bool styleC99 = mSettings.severity.isEnabled(Severity::style) && ((mTokenizer->isC() && mSettings.standards.c != Standards::C89) || (mTokenizer->isCPP() && mSettings.standards.cpp != Standards::CPP03)); + const bool printWarnings = mSettings.severity.isEnabled(Severity::warning); - if (!styleC99 && !printWarnings && !mSettings->isPremiumEnabled("wrongmathcall")) + if (!styleC99 && !printWarnings && !mSettings.isPremiumEnabled("wrongmathcall")) return; logChecker("CheckFunctions::checkMathFunctions"); // style,warning,c99,c++11 @@ -528,7 +528,7 @@ void CheckFunctionsImpl::memsetZeroBytes() // // - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckFunctions::memsetZeroBytes"); // warning @@ -567,8 +567,8 @@ void CheckFunctionsImpl::memsetInvalid2ndParam() // // - const bool printPortability = mSettings->severity.isEnabled(Severity::portability); - const bool printWarning = mSettings->severity.isEnabled(Severity::warning); + const bool printPortability = mSettings.severity.isEnabled(Severity::portability); + const bool printWarning = mSettings.severity.isEnabled(Severity::warning); if (!printWarning && !printPortability) return; @@ -596,8 +596,8 @@ void CheckFunctionsImpl::memsetInvalid2ndParam() if (printWarning && secondParamTok->isNumber()) { // Check if the second parameter is a literal and is out of range const MathLib::bigint value = MathLib::toBigNumber(secondParamTok); - const long long sCharMin = mSettings->platform.signedCharMin(); - const long long uCharMax = mSettings->platform.unsignedCharMax(); + const long long sCharMin = mSettings.platform.signedCharMin(); + const long long uCharMax = mSettings.platform.unsignedCharMax(); if (value < sCharMin || value > uCharMax) memsetValueOutOfRangeError(secondParamTok, secondParamTok->str()); } @@ -627,7 +627,7 @@ void CheckFunctionsImpl::memsetValueOutOfRangeError(const Token *tok, const std: void CheckFunctionsImpl::checkLibraryMatchFunctions() { - if (!mSettings->checkLibrary) + if (!mSettings.checkLibrary) return; bool insideNew = false; @@ -665,32 +665,32 @@ void CheckFunctionsImpl::checkLibraryMatchFunctions() if (Token::simpleMatch(tok->astParent(), ".")) { const Token* contTok = tok->astParent()->astOperand1(); - if (astContainerAction(contTok, mSettings->library) != Library::Container::Action::NO_ACTION) + if (astContainerAction(contTok, mSettings.library) != Library::Container::Action::NO_ACTION) continue; - if (astContainerYield(contTok, mSettings->library) != Library::Container::Yield::NO_YIELD) + if (astContainerYield(contTok, mSettings.library) != Library::Container::Yield::NO_YIELD) continue; } - if (!mSettings->library.isNotLibraryFunction(tok)) + if (!mSettings.library.isNotLibraryFunction(tok)) continue; - const std::string &functionName = mSettings->library.getFunctionName(tok); + const std::string &functionName = mSettings.library.getFunctionName(tok); if (functionName.empty()) continue; - if (mSettings->library.functions().find(functionName) != mSettings->library.functions().end()) + if (mSettings.library.functions().find(functionName) != mSettings.library.functions().end()) continue; - if (mSettings->library.podtype(tok->expressionString())) + if (mSettings.library.podtype(tok->expressionString())) continue; - if (mSettings->library.getTypeCheck("unusedvar", functionName) != Library::TypeCheck::def) + if (mSettings.library.getTypeCheck("unusedvar", functionName) != Library::TypeCheck::def) continue; const Token* start = tok; while (Token::Match(start->tokAt(-2), "%name% ::") && !start->tokAt(-2)->isKeyword()) start = start->tokAt(-2); - if (mSettings->library.detectContainerOrIterator(start)) + if (mSettings.library.detectContainerOrIterator(start)) continue; reportError(tok, @@ -705,10 +705,10 @@ void CheckFunctionsImpl::checkLibraryMatchFunctions() // details: https://en.cppreference.com/w/cpp/language/copy_elision void CheckFunctionsImpl::returnLocalStdMove() { - if (!mTokenizer->isCPP() || mSettings->standards.cpp < Standards::CPP11) + if (!mTokenizer->isCPP() || mSettings.standards.cpp < Standards::CPP11) return; - if (!mSettings->severity.isEnabled(Severity::performance)) + if (!mSettings.severity.isEnabled(Severity::performance)) return; logChecker("CheckFunctions::returnLocalStdMove"); // performance,c++11 @@ -744,7 +744,7 @@ void CheckFunctionsImpl::copyElisionError(const Token *tok) void CheckFunctionsImpl::useStandardLibrary() { - if (!mSettings->severity.isEnabled(Severity::style)) + if (!mSettings.severity.isEnabled(Severity::style)) return; logChecker("CheckFunctions::useStandardLibrary"); // style @@ -780,10 +780,10 @@ void CheckFunctionsImpl::useStandardLibrary() const auto& secondOp = condToken->str(); const bool isLess = "<" == secondOp && - isConstExpression(condToken->astOperand2(), mSettings->library) && + isConstExpression(condToken->astOperand2(), mSettings.library) && condToken->astOperand1()->varId() == idxVarId; const bool isMore = ">" == secondOp && - isConstExpression(condToken->astOperand1(), mSettings->library) && + isConstExpression(condToken->astOperand1(), mSettings.library) && condToken->astOperand2()->varId() == idxVarId; if (!(isLess || isMore)) @@ -855,7 +855,7 @@ void CheckFunctionsImpl::useStandardLibraryError(const Token *tok, const std::st void CheckFunctions::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckFunctionsImpl checkFunctions(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckFunctionsImpl checkFunctions(&tokenizer, tokenizer.getSettings(), errorLogger); checkFunctions.checkIgnoredReturnValue(); checkFunctions.checkMissingReturn(); // Missing "return" in exit path @@ -872,11 +872,11 @@ void CheckFunctions::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLog checkFunctions.useStandardLibrary(); } -void CheckFunctions::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckFunctions::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckFunctionsImpl c(nullptr, settings, errorLogger); - for (auto i = settings->library.functionwarn().cbegin(); i != settings->library.functionwarn().cend(); ++i) { + for (auto i = settings.library.functionwarn().cbegin(); i != settings.library.functionwarn().cend(); ++i) { c.functionCalledError(nullptr, Severity::style, i->first, i->second.message); } diff --git a/lib/checkfunctions.h b/lib/checkfunctions.h index 7ea9e2833a2..b6939ffb17f 100644 --- a/lib/checkfunctions.h +++ b/lib/checkfunctions.h @@ -54,7 +54,7 @@ class CPPCHECKLIB CheckFunctions : public Check { /** @brief Run checks against the normal token list */ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { return "Check function usage:\n" @@ -73,7 +73,7 @@ class CPPCHECKLIB CheckFunctions : public Check { class CPPCHECKLIB CheckFunctionsImpl : public CheckImpl { public: /** This constructor is used when running checks. */ - CheckFunctionsImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckFunctionsImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** Check for functions that should not be used */ diff --git a/lib/checkimpl.cpp b/lib/checkimpl.cpp index 43e56cfa360..2b28b829277 100644 --- a/lib/checkimpl.cpp +++ b/lib/checkimpl.cpp @@ -47,7 +47,7 @@ void CheckImpl::reportError(ErrorPath errorPath, Severity severity, const char i bool CheckImpl::wrongData(const Token *tok, const char *str) { - if (mSettings->daca) + if (mSettings.daca) reportError(tok, Severity::debug, "DacaWrongData", "Wrong data detected by condition " + std::string(str)); return true; } @@ -57,7 +57,7 @@ ErrorPath CheckImpl::getErrorPath(const Token* errtok, const ValueFlow::Value* v ErrorPath errorPath; if (!value) { errorPath.emplace_back(errtok, std::move(bug)); - } else if (mSettings->verbose || mSettings->outputFormat == Settings::OutputFormat::xml || !mSettings->templateLocation.empty()) { + } else if (mSettings.verbose || mSettings.outputFormat == Settings::OutputFormat::xml || !mSettings.templateLocation.empty()) { errorPath = value->errorPath; errorPath.emplace_back(errtok, std::move(bug)); } else { @@ -72,6 +72,6 @@ ErrorPath CheckImpl::getErrorPath(const Token* errtok, const ValueFlow::Value* v void CheckImpl::logChecker(const char id[]) { - if (!mSettings->buildDir.empty() || mSettings->collectLogCheckers()) + if (!mSettings.buildDir.empty() || mSettings.collectLogCheckers()) reportError(nullptr, Severity::internal, "logChecker", id); } diff --git a/lib/checkimpl.h b/lib/checkimpl.h index 35e70bbaae5..36f04a23d1f 100644 --- a/lib/checkimpl.h +++ b/lib/checkimpl.h @@ -37,7 +37,7 @@ class CPPCHECKLIB CheckImpl { protected: /** This constructor is used when running checks. */ - CheckImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : mTokenizer(tokenizer), mSettings(settings), mErrorLogger(errorLogger) {} public: @@ -46,7 +46,7 @@ class CPPCHECKLIB CheckImpl protected: const Tokenizer* const mTokenizer{}; - const Settings* const mSettings{}; + const Settings& mSettings; ErrorLogger* const mErrorLogger{}; /** report an error */ diff --git a/lib/checkinternal.cpp b/lib/checkinternal.cpp index 10af0543cec..f84203e5d0d 100644 --- a/lib/checkinternal.cpp +++ b/lib/checkinternal.cpp @@ -382,7 +382,7 @@ void CheckInternal::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogg if (!tokenizer.getSettings().checks.isEnabled(Checks::internalCheck)) return; - CheckInternalImpl checkInternal(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckInternalImpl checkInternal(&tokenizer, tokenizer.getSettings(), errorLogger); checkInternal.checkTokenMatchPatterns(); checkInternal.checkTokenSimpleMatchPatterns(); @@ -393,7 +393,7 @@ void CheckInternal::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogg checkInternal.checkRedundantTokCheck(); } -void CheckInternal::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckInternal::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckInternalImpl c(nullptr, settings, errorLogger); c.simplePatternError(nullptr, "class {", "Match"); diff --git a/lib/checkinternal.h b/lib/checkinternal.h index 2d95e3ed7e4..2b6267b4550 100644 --- a/lib/checkinternal.h +++ b/lib/checkinternal.h @@ -48,7 +48,7 @@ class CPPCHECKLIB CheckInternal : public Check { private: void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { // Don't include these checks on the WIKI where people can read what @@ -60,7 +60,7 @@ class CPPCHECKLIB CheckInternal : public Check { class CPPCHECKLIB CheckInternalImpl : public CheckImpl { public: /** This constructor is used when running checks. */ - CheckInternalImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckInternalImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** @brief %Check if a simple pattern is used inside Token::Match or Token::findmatch */ diff --git a/lib/checkio.cpp b/lib/checkio.cpp index f1cb4670c50..a62955d3017 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -121,9 +121,9 @@ namespace { void CheckIOImpl::checkFileUsage() { - const bool windows = mSettings->platform.isWindows(); - const bool printPortability = mSettings->severity.isEnabled(Severity::portability); - const bool printWarnings = mSettings->severity.isEnabled(Severity::warning); + const bool windows = mSettings.platform.isWindows(); + const bool printPortability = mSettings.severity.isEnabled(Severity::portability); + const bool printWarnings = mSettings.severity.isEnabled(Severity::warning); std::map filepointers; @@ -166,7 +166,7 @@ void CheckIOImpl::checkFileUsage() filepointer.second.lastOperation = Filepointer::Operation::UNKNOWN_OP; } } - } else if (tok->str() == "return" || tok->str() == "continue" || tok->str() == "break" || mSettings->library.isnoreturn(tok)) { // Reset upon return, continue or break + } else if (tok->str() == "return" || tok->str() == "continue" || tok->str() == "break" || mSettings.library.isnoreturn(tok)) { // Reset upon return, continue or break for (std::pair& filepointer : filepointers) { filepointer.second.mode_indent = 0; filepointer.second.mode = OpenMode::UNKNOWN_OM; @@ -258,7 +258,7 @@ void CheckIOImpl::checkFileUsage() } // Do not trigger a warning if the loop always exits or if the file is opened again in the loop. - if (!isReturnScope(bodyEnd, mSettings->library) && Token::findmatch(bodyStart, "%var% =", bodyEnd, fileTok->varId()) == nullptr) + if (!isReturnScope(bodyEnd, mSettings.library) && Token::findmatch(bodyStart, "%var% =", bodyEnd, fileTok->varId()) == nullptr) fcloseInLoopConditionError(tok, fileTok->str()); } } @@ -267,7 +267,7 @@ void CheckIOImpl::checkFileUsage() if ((tok->str() == "ungetc" || tok->str() == "ungetwc") && fileTok) fileTok = fileTok->nextArgument(); operation = Filepointer::Operation::UNIMPORTANT; - } else if (!Token::Match(tok, "if|for|while|catch|switch") && !mSettings->library.isFunctionConst(tok->str(), true)) { + } else if (!Token::Match(tok, "if|for|while|catch|switch") && !mSettings.library.isFunctionConst(tok->str(), true)) { const Token* const end2 = tok->linkAt(1); if (scope->functionOf && scope->functionOf->isClassOrStruct() && !scope->function->isStatic() && ((tok->strAt(-1) != "::" && tok->strAt(-1) != ".") || tok->strAt(-2) == "this")) { if (!tok->function() || (tok->function()->nestedIn && tok->function()->nestedIn->isClassOrStruct())) { @@ -436,7 +436,7 @@ void CheckIOImpl::incompatibleFileOpenError(const Token *tok, const std::string //--------------------------------------------------------------------------- void CheckIOImpl::invalidScanf() { - if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("invalidscanf")) + if (!mSettings.severity.isEnabled(Severity::warning) && !mSettings.isPremiumEnabled("invalidscanf")) return; logChecker("CheckIO::invalidScanf"); @@ -556,7 +556,7 @@ static inline bool typesMatch(const std::string& iToTest, const std::string& iTy void CheckIOImpl::checkWrongPrintfScanfArguments() { const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); - const bool isWindows = mSettings->platform.isWindows(); + const bool isWindows = mSettings.platform.isWindows(); logChecker("CheckIO::checkWrongPrintfScanfArguments"); @@ -571,10 +571,10 @@ void CheckIOImpl::checkWrongPrintfScanfArguments() bool scanf_s = false; int formatStringArgNo = -1; - if (tok->strAt(1) == "(" && mSettings->library.formatstr_function(tok)) { - formatStringArgNo = mSettings->library.formatstr_argno(tok); - scan = mSettings->library.formatstr_scan(tok); - scanf_s = mSettings->library.formatstr_secure(tok); + if (tok->strAt(1) == "(" && mSettings.library.formatstr_function(tok)) { + formatStringArgNo = mSettings.library.formatstr_argno(tok); + scan = mSettings.library.formatstr_scan(tok); + scanf_s = mSettings.library.formatstr_secure(tok); } if (formatStringArgNo >= 0) { @@ -631,8 +631,8 @@ void CheckIOImpl::checkFormatString(const Token * const tok, const bool scan, const bool scanf_s) { - const bool isWindows = mSettings->platform.isWindows(); - const bool printWarning = mSettings->severity.isEnabled(Severity::warning); + const bool isWindows = mSettings.platform.isWindows(); + const bool printWarning = mSettings.severity.isEnabled(Severity::warning); const std::string &formatString = formatStringTok->str(); // Count format string parameters.. @@ -722,9 +722,9 @@ void CheckIOImpl::checkFormatString(const Token * const tok, } // Perform type checks - ArgumentInfo argInfo(argListTok, *mSettings, mTokenizer->isCPP()); + ArgumentInfo argInfo(argListTok, mSettings, mTokenizer->isCPP()); - if ((argInfo.typeToken && !argInfo.isLibraryType(*mSettings)) || *i == ']') { + if ((argInfo.typeToken && !argInfo.isLibraryType(mSettings)) || *i == ']') { if (scan) { std::string specifier; bool done = false; @@ -1737,7 +1737,7 @@ void CheckIOImpl::wrongPrintfScanfArgumentsError(const Token* tok, nonneg int numFunction) { const Severity severity = numFormat > numFunction ? Severity::error : Severity::warning; - if (severity != Severity::error && !mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("wrongPrintfScanfArgNum")) + if (severity != Severity::error && !mSettings.severity.isEnabled(Severity::warning) && !mSettings.isPremiumEnabled("wrongPrintfScanfArgNum")) return; std::ostringstream errmsg; @@ -1756,7 +1756,7 @@ void CheckIOImpl::wrongPrintfScanfArgumentsError(const Token* tok, void CheckIOImpl::wrongPrintfScanfPosixParameterPositionError(const Token* tok, const std::string& functionName, nonneg int index, nonneg int numFunction) { - if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("wrongPrintfScanfParameterPositionError")) + if (!mSettings.severity.isEnabled(Severity::warning) && !mSettings.isPremiumEnabled("wrongPrintfScanfParameterPositionError")) return; std::ostringstream errmsg; errmsg << functionName << ": "; @@ -1771,7 +1771,7 @@ void CheckIOImpl::wrongPrintfScanfPosixParameterPositionError(const Token* tok, void CheckIOImpl::invalidScanfArgTypeError_s(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo) { const Severity severity = getSeverity(argInfo); - if (!mSettings->severity.isEnabled(severity)) + if (!mSettings.severity.isEnabled(severity)) return; std::ostringstream errmsg; errmsg << "%" << specifier << " in format string (no. " << numFormat << ") requires a \'"; @@ -1787,7 +1787,7 @@ void CheckIOImpl::invalidScanfArgTypeError_s(const Token* tok, nonneg int numFor void CheckIOImpl::invalidScanfArgTypeError_int(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo, bool isUnsigned) { const Severity severity = getSeverity(argInfo); - if (!mSettings->severity.isEnabled(severity)) + if (!mSettings.severity.isEnabled(severity)) return; std::ostringstream errmsg; errmsg << "%" << specifier << " in format string (no. " << numFormat << ") requires \'"; @@ -1832,7 +1832,7 @@ void CheckIOImpl::invalidScanfArgTypeError_int(const Token* tok, nonneg int numF void CheckIOImpl::invalidScanfArgTypeError_float(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo) { const Severity severity = getSeverity(argInfo); - if (!mSettings->severity.isEnabled(severity)) + if (!mSettings.severity.isEnabled(severity)) return; std::ostringstream errmsg; errmsg << "%" << specifier << " in format string (no. " << numFormat << ") requires \'"; @@ -1851,7 +1851,7 @@ void CheckIOImpl::invalidScanfArgTypeError_float(const Token* tok, nonneg int nu void CheckIOImpl::invalidPrintfArgTypeError_s(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo) { const Severity severity = getSeverity(argInfo); - if (!mSettings->severity.isEnabled(severity)) + if (!mSettings.severity.isEnabled(severity)) return; std::ostringstream errmsg; errmsg << "%s in format string (no. " << numFormat << ") requires \'char *\' but the argument type is "; @@ -1862,7 +1862,7 @@ void CheckIOImpl::invalidPrintfArgTypeError_s(const Token* tok, nonneg int numFo void CheckIOImpl::invalidPrintfArgTypeError_n(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo) { const Severity severity = getSeverity(argInfo); - if (!mSettings->severity.isEnabled(severity)) + if (!mSettings.severity.isEnabled(severity)) return; std::ostringstream errmsg; errmsg << "%n in format string (no. " << numFormat << ") requires \'int *\' but the argument type is "; @@ -1873,7 +1873,7 @@ void CheckIOImpl::invalidPrintfArgTypeError_n(const Token* tok, nonneg int numFo void CheckIOImpl::invalidPrintfArgTypeError_p(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo) { const Severity severity = getSeverity(argInfo); - if (!mSettings->severity.isEnabled(severity)) + if (!mSettings.severity.isEnabled(severity)) return; std::ostringstream errmsg; errmsg << "%p in format string (no. " << numFormat << ") requires an address but the argument type is "; @@ -1923,7 +1923,7 @@ static void printfFormatType(std::ostream& os, const std::string& specifier, boo void CheckIOImpl::invalidPrintfArgTypeError_uint(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo) { const Severity severity = getSeverity(argInfo); - if (!mSettings->severity.isEnabled(severity)) + if (!mSettings.severity.isEnabled(severity)) return; std::ostringstream errmsg; errmsg << "%" << specifier << " in format string (no. " << numFormat << ") requires "; @@ -1937,7 +1937,7 @@ void CheckIOImpl::invalidPrintfArgTypeError_uint(const Token* tok, nonneg int nu void CheckIOImpl::invalidPrintfArgTypeError_sint(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo) { const Severity severity = getSeverity(argInfo); - if (!mSettings->severity.isEnabled(severity)) + if (!mSettings.severity.isEnabled(severity)) return; std::ostringstream errmsg; errmsg << "%" << specifier << " in format string (no. " << numFormat << ") requires "; @@ -1950,7 +1950,7 @@ void CheckIOImpl::invalidPrintfArgTypeError_sint(const Token* tok, nonneg int nu void CheckIOImpl::invalidPrintfArgTypeError_float(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo) { const Severity severity = getSeverity(argInfo); - if (!mSettings->severity.isEnabled(severity)) + if (!mSettings.severity.isEnabled(severity)) return; std::ostringstream errmsg; errmsg << "%" << specifier << " in format string (no. " << numFormat << ") requires \'"; @@ -2019,7 +2019,7 @@ void CheckIOImpl::argumentType(std::ostream& os, const ArgumentInfo * argInfo) void CheckIOImpl::invalidLengthModifierError(const Token* tok, nonneg int numFormat, const std::string& modifier) { - if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("invalidLengthModifierError")) + if (!mSettings.severity.isEnabled(Severity::warning) && !mSettings.isPremiumEnabled("invalidLengthModifierError")) return; std::ostringstream errmsg; errmsg << "'" << modifier << "' in format string (no. " << numFormat << ") is a length modifier and cannot be used without a conversion specifier."; @@ -2038,7 +2038,7 @@ void CheckIOImpl::invalidScanfFormatWidthError(const Token* tok, nonneg int numF std::ostringstream errmsg; if (arrlen > width) { - if (tok != nullptr && (!mSettings->certainty.isEnabled(Certainty::inconclusive) || !mSettings->severity.isEnabled(Severity::warning))) + if (tok != nullptr && (!mSettings.certainty.isEnabled(Certainty::inconclusive) || !mSettings.severity.isEnabled(Severity::warning))) return; errmsg << "Width " << width << " given in format string (no. " << numFormat << ") is smaller than destination buffer" << " '" << varname << "[" << arrlen << "]'."; @@ -2052,7 +2052,7 @@ void CheckIOImpl::invalidScanfFormatWidthError(const Token* tok, nonneg int numF void CheckIO::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckIOImpl checkIO(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckIOImpl checkIO(&tokenizer, tokenizer.getSettings(), errorLogger); checkIO.checkWrongPrintfScanfArguments(); checkIO.checkCoutCerrMisusage(); @@ -2060,7 +2060,7 @@ void CheckIO::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) checkIO.invalidScanf(); } -void CheckIO::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckIO::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckIOImpl c(nullptr, settings, errorLogger); c.coutCerrMisusageError(nullptr, "cout"); diff --git a/lib/checkio.h b/lib/checkio.h index acad40de136..4642feac511 100644 --- a/lib/checkio.h +++ b/lib/checkio.h @@ -52,7 +52,7 @@ class CPPCHECKLIB CheckIO : public Check { /** @brief Run checks on the normal token list */ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { return "Check format string input/output operations.\n" @@ -72,7 +72,7 @@ class CPPCHECKLIB CheckIO : public Check { class CPPCHECKLIB CheckIOImpl : public CheckImpl { public: /** @brief This constructor is used when running checks. */ - CheckIOImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckIOImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** @brief %Check for missusage of std::cout */ diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 7e12872c3d4..11d1086ee5d 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -137,9 +137,9 @@ void CheckLeakAutoVarImpl::deallocReturnError(const Token *tok, const Token *dea void CheckLeakAutoVarImpl::configurationInfo(const Token* tok, const std::pair& functionUsage) { - if (mSettings->checkLibrary && functionUsage.second == VarInfo::USED && + if (mSettings.checkLibrary && functionUsage.second == VarInfo::USED && (!functionUsage.first || !functionUsage.first->function() || !functionUsage.first->function()->hasBody())) { - std::string funcStr = functionUsage.first ? mSettings->library.getFunctionName(functionUsage.first) : "f"; + std::string funcStr = functionUsage.first ? mSettings.library.getFunctionName(functionUsage.first) : "f"; if (funcStr.empty()) funcStr = "unknown::" + functionUsage.first->str(); reportError(tok, @@ -162,7 +162,7 @@ void CheckLeakAutoVarImpl::doubleFreeError(const Token *tok, const Token *prevFr void CheckLeakAutoVarImpl::check() { - if (mSettings->clang) + if (mSettings.clang) return; logChecker("CheckLeakAutoVar::check"); // notclang @@ -381,7 +381,7 @@ bool CheckLeakAutoVarImpl::checkScope(const Token * const startToken, ftok = ftok->tokAt(2); // bailout for variable passed to library function with out parameter - if (const Library::Function *libFunc = mSettings->library.getFunction(ftok)) { + if (const Library::Function *libFunc = mSettings.library.getFunction(ftok)) { using ArgumentChecks = Library::ArgumentChecks; using Direction = ArgumentChecks::Direction; const std::vector args = getArguments(ftok); @@ -479,7 +479,7 @@ bool CheckLeakAutoVarImpl::checkScope(const Token * const startToken, // allocation? const Token *const fTok = tokRightAstOperand ? tokRightAstOperand->previous() : nullptr; if (Token::Match(fTok, "%type% (")) { - const Library::AllocFunc* f = mSettings->library.getAllocFuncInfo(fTok); + const Library::AllocFunc* f = mSettings.library.getAllocFuncInfo(fTok); if (f && f->arg == -1) { VarInfo::AllocInfo& varAlloc = alloctype[varTok->varId()]; varAlloc.type = f->groupId; @@ -545,7 +545,7 @@ bool CheckLeakAutoVarImpl::checkScope(const Token * const startToken, tokRightAstOperand = tokRightAstOperand->astOperand2() ? tokRightAstOperand->astOperand2() : tokRightAstOperand->astOperand1(); if (tokRightAstOperand && Token::Match(tokRightAstOperand->previous(), "%type% (")) { const Token * fTok = tokRightAstOperand->previous(); - const Library::AllocFunc* f = mSettings->library.getAllocFuncInfo(fTok); + const Library::AllocFunc* f = mSettings.library.getAllocFuncInfo(fTok); if (f && f->arg == -1) { VarInfo::AllocInfo& varAlloc = alloctype[innerTok->varId()]; varAlloc.type = f->groupId; @@ -568,7 +568,7 @@ bool CheckLeakAutoVarImpl::checkScope(const Token * const startToken, // check for function call if (openingPar) { - const Library::AllocFunc* allocFunc = mSettings->library.getDeallocFuncInfo(innerTok); + const Library::AllocFunc* allocFunc = mSettings.library.getDeallocFuncInfo(innerTok); // innerTok is a function name const VarInfo::AllocInfo allocation(0, VarInfo::NOALLOC); functionCall(innerTok, openingPar, varInfo, allocation, allocFunc); @@ -623,7 +623,7 @@ bool CheckLeakAutoVarImpl::checkScope(const Token * const startToken, if (std::any_of(varInfo1.alloctype.begin(), varInfo1.alloctype.end(), [&](const std::pair& info) { if (info.second.status != VarInfo::ALLOC) return false; - const Token* ret = getReturnValueFromOutparamAlloc(info.second.allocTok, *mSettings); + const Token* ret = getReturnValueFromOutparamAlloc(info.second.allocTok, mSettings); return ret && vartok && ret->varId() && ret->varId() == vartok->varId(); })) { varInfo1.clear(); @@ -755,7 +755,7 @@ bool CheckLeakAutoVarImpl::checkScope(const Token * const startToken, // Function call.. else if (const Token* openingPar = isFunctionCall(ftok)) { - const Library::AllocFunc* af = mSettings->library.getDeallocFuncInfo(ftok); + const Library::AllocFunc* af = mSettings.library.getDeallocFuncInfo(ftok); VarInfo::AllocInfo allocation(af ? af->groupId : 0, VarInfo::DEALLOC, ftok); if (allocation.type == 0) allocation.status = VarInfo::NOALLOC; @@ -776,8 +776,8 @@ bool CheckLeakAutoVarImpl::checkScope(const Token * const startToken, if (ftok->function() && !ftok->function()->isAttributeNoreturn() && !(ftok->function()->functionScope && mTokenizer->isScopeNoReturn(ftok->function()->functionScope->bodyEnd))) // check function scope continue; - const std::string functionName(mSettings->library.getFunctionName(ftok)); - if (!mSettings->library.isLeakIgnore(functionName) && !mSettings->library.isUse(functionName)) { + const std::string functionName(mSettings.library.getFunctionName(ftok)); + if (!mSettings.library.isLeakIgnore(functionName) && !mSettings.library.isUse(functionName)) { const VarInfo::Usage usage = Token::simpleMatch(openingPar, "( )") ? VarInfo::NORET : VarInfo::USED; // TODO: check parameters passed to function varInfo.possibleUsageAll({ ftok, usage }); } @@ -800,7 +800,7 @@ bool CheckLeakAutoVarImpl::checkScope(const Token * const startToken, } // Check smart pointer - else if (Token::Match(ftok, "%name% <") && mSettings->library.isSmartPointer(tok)) { + else if (Token::Match(ftok, "%name% <") && mSettings.library.isSmartPointer(tok)) { const Token * typeEndTok = ftok->linkAt(1); if (!Token::Match(typeEndTok, "> %var% {|( %var% ,|)|}")) continue; @@ -835,7 +835,7 @@ bool CheckLeakAutoVarImpl::checkScope(const Token * const startToken, const Token * dtok = Token::findmatch(deleterToken, "& %name%", endDeleterToken); if (dtok) { dtok = dtok->next(); - af = mSettings->library.getDeallocFuncInfo(dtok); + af = mSettings.library.getDeallocFuncInfo(dtok); } if (!dtok || !af) { const Token * tscopeStart = nullptr; @@ -865,7 +865,7 @@ bool CheckLeakAutoVarImpl::checkScope(const Token * const startToken, if (tscopeStart && tscopeEnd) { for (const Token *tok2 = tscopeStart; tok2 != tscopeEnd; tok2 = tok2->next()) { - af = mSettings->library.getDeallocFuncInfo(tok2); + af = mSettings.library.getDeallocFuncInfo(tok2); if (af) break; } @@ -896,7 +896,7 @@ const Token * CheckLeakAutoVarImpl::checkTokenInsideExpression(const Token * con if (var != varInfo.alloctype.end()) { bool unknown = false; if (var->second.status == VarInfo::DEALLOC && tok->valueType() && tok->valueType()->pointer && - CheckNullPointerImpl::isPointerDeRef(tok, unknown, *mSettings, /*checkNullArg*/ false) && !unknown) { + CheckNullPointerImpl::isPointerDeRef(tok, unknown, mSettings, /*checkNullArg*/ false) && !unknown) { deallocUseError(tok, tok->str()); } else if (Token::simpleMatch(tok->tokAt(-2), "= &")) { varInfo.erase(tok->varId()); @@ -917,9 +917,9 @@ const Token * CheckLeakAutoVarImpl::checkTokenInsideExpression(const Token * con if ((rhs->str() == "." || rhs->varId() == tok->varId()) && isAssignment) { // simple assignment varInfo.erase(tok->varId()); - } else if (rhs->astParent() && rhs->str() == "(" && !mSettings->library.returnValue(rhs->astOperand1()).empty()) { + } else if (rhs->astParent() && rhs->str() == "(" && !mSettings.library.returnValue(rhs->astOperand1()).empty()) { // #9298, assignment through return value of a function - const std::string &returnValue = mSettings->library.returnValue(rhs->astOperand1()); + const std::string &returnValue = mSettings.library.returnValue(rhs->astOperand1()); if (startsWith(returnValue, "arg")) { int argn; const Token *func = getTokenArgumentFunction(tok, argn); @@ -940,12 +940,12 @@ const Token * CheckLeakAutoVarImpl::checkTokenInsideExpression(const Token * con // check for function call const Token * const openingPar = inFuncCall ? nullptr : isFunctionCall(tok); if (openingPar) { - const Library::AllocFunc* allocFunc = mSettings->library.getDeallocFuncInfo(tok); + const Library::AllocFunc* allocFunc = mSettings.library.getDeallocFuncInfo(tok); VarInfo::AllocInfo alloc(allocFunc ? allocFunc->groupId : 0, VarInfo::DEALLOC, tok); if (alloc.type == 0) alloc.status = VarInfo::NOALLOC; functionCall(tok, openingPar, varInfo, alloc, nullptr); - const std::string &returnValue = mSettings->library.returnValue(tok); + const std::string &returnValue = mSettings.library.returnValue(tok); if (startsWith(returnValue, "arg")) // the function returns one of its argument, we need to process a potential assignment return openingPar; @@ -958,7 +958,7 @@ const Token * CheckLeakAutoVarImpl::checkTokenInsideExpression(const Token * con void CheckLeakAutoVarImpl::changeAllocStatusIfRealloc(std::map &alloctype, const Token *fTok, const Token *retTok) const { - const Library::AllocFunc* f = mSettings->library.getReallocFuncInfo(fTok); + const Library::AllocFunc* f = mSettings.library.getReallocFuncInfo(fTok); if (f && f->arg == -1 && f->reallocArg > 0 && f->reallocArg <= numberOfArguments(fTok)) { const Token* argTok = getArguments(fTok).at(f->reallocArg - 1); if (alloctype.find(argTok->varId()) != alloctype.end()) { @@ -984,7 +984,7 @@ void CheckLeakAutoVarImpl::changeAllocStatus(VarInfo &varInfo, const VarInfo::Al if (var != alloctype.end()) { // bailout if function is also allocating, since the argument might be moved // to the return value, such as in fdopen - if (allocation.allocTok && mSettings->library.getAllocFuncInfo(allocation.allocTok)) { + if (allocation.allocTok && mSettings.library.getAllocFuncInfo(allocation.allocTok)) { varInfo.erase(arg->varId()); return; } @@ -1017,8 +1017,8 @@ void CheckLeakAutoVarImpl::changeAllocStatus(VarInfo &varInfo, const VarInfo::Al void CheckLeakAutoVarImpl::functionCall(const Token *tokName, const Token *tokOpeningPar, VarInfo &varInfo, const VarInfo::AllocInfo& allocation, const Library::AllocFunc* af) { // Ignore function call? - const bool isLeakIgnore = mSettings->library.isLeakIgnore(mSettings->library.getFunctionName(tokName)); - if (mSettings->library.getReallocFuncInfo(tokName)) + const bool isLeakIgnore = mSettings.library.isLeakIgnore(mSettings.library.getFunctionName(tokName)); + if (mSettings.library.getReallocFuncInfo(tokName)) return; if (tokName->next()->valueType() && tokName->next()->valueType()->container && tokName->next()->valueType()->container->stdStringLike) return; @@ -1069,10 +1069,10 @@ void CheckLeakAutoVarImpl::functionCall(const Token *tokName, const Token *tokOp // Is variable allocated? if (!isnull && (!af || af->arg == argNr)) { - const Library::AllocFunc* deallocFunc = mSettings->library.getDeallocFuncInfo(tokName); + const Library::AllocFunc* deallocFunc = mSettings.library.getDeallocFuncInfo(tokName); VarInfo::AllocInfo dealloc(deallocFunc ? deallocFunc->groupId : 0, VarInfo::DEALLOC, tokName); - if (const Library::AllocFunc* allocFunc = mSettings->library.getAllocFuncInfo(tokName)) { - if (mSettings->library.getDeallocFuncInfo(tokName)) { + if (const Library::AllocFunc* allocFunc = mSettings.library.getAllocFuncInfo(tokName)) { + if (mSettings.library.getDeallocFuncInfo(tokName)) { changeAllocStatus(varInfo, dealloc.type == 0 ? allocation : dealloc, tokName, arg); } if (allocFunc->arg == argNr && @@ -1092,7 +1092,7 @@ void CheckLeakAutoVarImpl::functionCall(const Token *tokName, const Token *tokOp } } // Check smart pointer - else if (Token::Match(arg, "%name% < %type%") && mSettings->library.isSmartPointer(argTypeStartTok)) { + else if (Token::Match(arg, "%name% < %type%") && mSettings.library.isSmartPointer(argTypeStartTok)) { const Token * typeEndTok = arg->linkAt(1); const Token * allocTok = nullptr; if (!Token::Match(typeEndTok, "> {|( %var% ,|)|}")) @@ -1117,14 +1117,14 @@ void CheckLeakAutoVarImpl::functionCall(const Token *tokName, const Token *tokOp // Check if its a pointer to a function const Token * dtok = Token::findmatch(deleterToken, "& %name%", endDeleterToken); if (dtok) { - sp_af = mSettings->library.getDeallocFuncInfo(dtok->tokAt(1)); + sp_af = mSettings.library.getDeallocFuncInfo(dtok->tokAt(1)); } else { // If the deleter is a class, check if class calls the dealloc function dtok = Token::findmatch(deleterToken, "%type%", endDeleterToken); if (dtok && dtok->type()) { const Scope * tscope = dtok->type()->classScope; for (const Token *tok2 = tscope->bodyStart; tok2 != tscope->bodyEnd; tok2 = tok2->next()) { - sp_af = mSettings->library.getDeallocFuncInfo(tok2); + sp_af = mSettings.library.getDeallocFuncInfo(tok2); if (sp_af) { allocTok = tok2; break; @@ -1209,7 +1209,7 @@ void CheckLeakAutoVarImpl::ret(const Token *tok, VarInfo &varInfo, const bool is while (tok3 && tok3->isCast() && (!tok3->valueType() || tok3->valueType()->pointer || - isSafeCast(tok3->valueType(), *mSettings))) + isSafeCast(tok3->valueType(), mSettings))) tok3 = tok3->astOperand2() ? tok3->astOperand2() : tok3->astOperand1(); if (tok3 && tok3->varId() == varid) tok2 = tok3->next(); @@ -1232,7 +1232,7 @@ void CheckLeakAutoVarImpl::ret(const Token *tok, VarInfo &varInfo, const bool is // don't warn when returning after checking return value of outparam allocation const Token* outparamFunc{}; if ((tok->scope()->type == ScopeType::eIf || tok->scope()->type== ScopeType::eElse) && - (outparamFunc = getOutparamAllocation(it->second.allocTok, *mSettings))) { + (outparamFunc = getOutparamAllocation(it->second.allocTok, mSettings))) { const Scope* scope = tok->scope(); if (scope->type == ScopeType::eElse) { scope = scope->bodyStart->tokAt(-2)->scope(); @@ -1280,11 +1280,11 @@ void CheckLeakAutoVarImpl::ret(const Token *tok, VarInfo &varInfo, const bool is void CheckLeakAutoVar::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckLeakAutoVarImpl checkLeakAutoVar(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckLeakAutoVarImpl checkLeakAutoVar(&tokenizer, tokenizer.getSettings(), errorLogger); checkLeakAutoVar.check(); } -void CheckLeakAutoVar::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckLeakAutoVar::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckLeakAutoVarImpl c(nullptr, settings, errorLogger); c.deallocReturnError(nullptr, nullptr, "p"); diff --git a/lib/checkleakautovar.h b/lib/checkleakautovar.h index ce7e1ddbd8b..c12c03b6a09 100644 --- a/lib/checkleakautovar.h +++ b/lib/checkleakautovar.h @@ -113,7 +113,7 @@ class CPPCHECKLIB CheckLeakAutoVar : public Check { private: void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { return "Detect when a auto variable is allocated but not deallocated or deallocated twice.\n"; @@ -123,7 +123,7 @@ class CPPCHECKLIB CheckLeakAutoVar : public Check { class CPPCHECKLIB CheckLeakAutoVarImpl : public CheckImpl { public: /** This constructor is used when running checks. */ - CheckLeakAutoVarImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckLeakAutoVarImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** check for leaks in all scopes */ diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index cef03b1a538..0286884ab16 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -95,7 +95,7 @@ CheckMemoryLeakImpl::AllocType CheckMemoryLeakImpl::getAllocationType(const Toke return New; } - if (mSettings->hasLib("posix")) { + if (mSettings.hasLib("posix")) { if (Token::Match(tok2, "open|openat|creat|mkstemp|mkostemp|socket (")) { // simple sanity check of function parameters.. // TODO: Make such check for all these functions @@ -114,11 +114,11 @@ CheckMemoryLeakImpl::AllocType CheckMemoryLeakImpl::getAllocationType(const Toke } // Does tok2 point on a Library allocation function? - const int alloctype = mSettings->library.getAllocId(tok2, -1); + const int alloctype = mSettings.library.getAllocId(tok2, -1); if (alloctype > 0) { - if (alloctype == mSettings->library.deallocId("free")) + if (alloctype == mSettings.library.deallocId("free")) return Malloc; - if (alloctype == mSettings->library.deallocId("fclose")) + if (alloctype == mSettings.library.deallocId("fclose")) return File; return Library::ismemory(alloctype) ? OtherMem : OtherRes; } @@ -159,7 +159,7 @@ CheckMemoryLeakImpl::AllocType CheckMemoryLeakImpl::getReallocationType(const To if (!Token::Match(tok2, "%name% (")) return No; - const Library::AllocFunc *f = mSettings->library.getReallocFuncInfo(tok2); + const Library::AllocFunc *f = mSettings.library.getReallocFuncInfo(tok2); if (!(f && f->reallocArg > 0 && f->reallocArg <= numberOfArguments(tok2))) return No; const auto args = getArguments(tok2); @@ -173,11 +173,11 @@ CheckMemoryLeakImpl::AllocType CheckMemoryLeakImpl::getReallocationType(const To if (varid > 0 && !Token::Match(arg, "%varid% [,)]", varid)) return No; - const int realloctype = mSettings->library.getReallocId(tok2, -1); + const int realloctype = mSettings.library.getReallocId(tok2, -1); if (realloctype > 0) { - if (realloctype == mSettings->library.deallocId("free")) + if (realloctype == mSettings.library.deallocId("free")) return Malloc; - if (realloctype == mSettings->library.deallocId("fclose")) + if (realloctype == mSettings.library.deallocId("fclose")) return File; return Library::ismemory(realloctype) ? OtherMem : OtherRes; } @@ -216,7 +216,7 @@ CheckMemoryLeakImpl::AllocType CheckMemoryLeakImpl::getDeallocationType(const To if (tok->str() == "realloc" && Token::simpleMatch(vartok->next(), ", 0 )")) return Malloc; - if (mSettings->hasLib("posix")) { + if (mSettings.hasLib("posix")) { if (tok->str() == "close") return Fd; if (tok->str() == "pclose") @@ -224,11 +224,11 @@ CheckMemoryLeakImpl::AllocType CheckMemoryLeakImpl::getDeallocationType(const To } // Does tok point on a Library deallocation function? - const int dealloctype = mSettings->library.getDeallocId(tok, argNr); + const int dealloctype = mSettings.library.getDeallocId(tok, argNr); if (dealloctype > 0) { - if (dealloctype == mSettings->library.deallocId("free")) + if (dealloctype == mSettings.library.deallocId("free")) return Malloc; - if (dealloctype == mSettings->library.deallocId("fclose")) + if (dealloctype == mSettings.library.deallocId("fclose")) return File; return Library::ismemory(dealloctype) ? OtherMem : OtherRes; } @@ -243,7 +243,7 @@ CheckMemoryLeakImpl::AllocType CheckMemoryLeakImpl::getDeallocationType(const To bool CheckMemoryLeakImpl::isReopenStandardStream(const Token *tok) const { if (getReallocationType(tok, 0) == File) { - const Library::AllocFunc *f = mSettings->library.getReallocFuncInfo(tok); + const Library::AllocFunc *f = mSettings.library.getReallocFuncInfo(tok); if (f && f->reallocArg > 0 && f->reallocArg <= numberOfArguments(tok)) { const Token* arg = getArguments(tok).at(f->reallocArg - 1); if (Token::Match(arg, "stdin|stdout|stderr")) @@ -255,7 +255,7 @@ bool CheckMemoryLeakImpl::isReopenStandardStream(const Token *tok) const bool CheckMemoryLeakImpl::isOpenDevNull(const Token *tok) const { - if (mSettings->hasLib("posix") && tok->str() == "open" && numberOfArguments(tok) == 2) { + if (mSettings.hasLib("posix") && tok->str() == "open" && numberOfArguments(tok) == 2) { const Token* arg = getArguments(tok).at(0); if (Token::simpleMatch(arg, "\"/dev/null\"")) return true; @@ -440,8 +440,8 @@ void CheckMemoryLeakInFunctionImpl::checkReallocUsage() const Token *const reallocTok = parTok->astOperand1(); if (!reallocTok) continue; - const Library::AllocFunc* f = mSettings->library.getReallocFuncInfo(reallocTok); - if (!(f && f->arg == -1 && mSettings->library.isnotnoreturn(reallocTok))) + const Library::AllocFunc* f = mSettings.library.getReallocFuncInfo(reallocTok); + if (!(f && f->arg == -1 && mSettings.library.isnotnoreturn(reallocTok))) continue; const AllocType allocType = getReallocationType(reallocTok, tok->varId()); @@ -467,7 +467,7 @@ void CheckMemoryLeakInFunctionImpl::checkReallocUsage() Token::findmatch(scope->bodyStart, "[{};] %varid% = *| %var%", tok, tok->varId())) continue; if (const Token* storeTok = Token::findmatch(scope->bodyStart, "[{};] %varid% = %name% (", tok, tok->varId())) - if (storeTok->tokAt(3) != reallocTok && !mSettings->library.getAllocFuncInfo(storeTok->tokAt(3))) + if (storeTok->tokAt(3) != reallocTok && !mSettings.library.getAllocFuncInfo(storeTok->tokAt(3))) continue; // Check if the argument is known to be null, which means it is not a memory leak @@ -492,11 +492,11 @@ void CheckMemoryLeakInFunctionImpl::checkReallocUsage() void CheckMemoryLeakInFunction::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckMemoryLeakInFunctionImpl checkMemoryLeak(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckMemoryLeakInFunctionImpl checkMemoryLeak(&tokenizer, tokenizer.getSettings(), errorLogger); checkMemoryLeak.checkReallocUsage(); } -void CheckMemoryLeakInFunction::getErrorMessages(ErrorLogger *e, const Settings *settings) const +void CheckMemoryLeakInFunction::getErrorMessages(ErrorLogger *e, const Settings &settings) const { CheckMemoryLeakInFunctionImpl c(nullptr, settings, e); c.memleakError(nullptr, "varname"); @@ -629,7 +629,7 @@ void CheckMemoryLeakInClassImpl::variable(const Scope *scope, const Token *tokVa } // Function call .. possible deallocation - else if (Token::Match(tok->previous(), "[{};] %name% (") && !tok->isKeyword() && !mSettings->library.isLeakIgnore(tok->str())) { + else if (Token::Match(tok->previous(), "[{};] %name% (") && !tok->isKeyword() && !mSettings.library.isLeakIgnore(tok->str())) { return; } } @@ -645,7 +645,7 @@ void CheckMemoryLeakInClassImpl::variable(const Scope *scope, const Token *tokVa void CheckMemoryLeakInClassImpl::unsafeClassError(const Token *tok, const std::string &classname, const std::string &varname) { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("unsafeClassCanLeak")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("unsafeClassCanLeak")) return; reportError(tok, Severity::style, "unsafeClassCanLeak", @@ -661,7 +661,7 @@ void CheckMemoryLeakInClassImpl::checkPublicFunctions(const Scope *scope, const // Check that public functions deallocate the pointers that they allocate. // There is no checking how these functions are used and therefore it // isn't established if there is real leaks or not. - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; const int varid = classtok->varId(); @@ -696,11 +696,11 @@ void CheckMemoryLeakInClass::runChecks(const Tokenizer &tokenizer, ErrorLogger * if (!tokenizer.isCPP()) return; - CheckMemoryLeakInClassImpl checkMemoryLeak(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckMemoryLeakInClassImpl checkMemoryLeak(&tokenizer, tokenizer.getSettings(), errorLogger); checkMemoryLeak.check(); } -void CheckMemoryLeakInClass::getErrorMessages(ErrorLogger *e, const Settings *settings) const +void CheckMemoryLeakInClass::getErrorMessages(ErrorLogger *e, const Settings &settings) const { CheckMemoryLeakInClassImpl c(nullptr, settings, e); c.publicAllocationError(nullptr, "varname"); @@ -709,7 +709,7 @@ void CheckMemoryLeakInClass::getErrorMessages(ErrorLogger *e, const Settings *se void CheckMemoryLeakStructMemberImpl::check() { - if (mSettings->clang) + if (mSettings.clang) return; logChecker("CheckMemoryLeakStructMember::check"); @@ -739,7 +739,7 @@ bool CheckMemoryLeakStructMemberImpl::isMalloc(const Variable *variable) const const Token* tok3 = tok2->tokAt(1)->astOperand2(); while (tok3 && tok3->isCast()) tok3 = tok3->astOperand2() ? tok3->astOperand2() : tok3->astOperand1(); - if ((tok3 && Token::Match(tok3->tokAt(-1), "%name% (") && mSettings->library.getAllocFuncInfo(tok3->tokAt(-1))) || + if ((tok3 && Token::Match(tok3->tokAt(-1), "%name% (") && mSettings.library.getAllocFuncInfo(tok3->tokAt(-1))) || (Token::simpleMatch(tok3, "new") && tok3->isCpp())) { alloc = true; } @@ -767,7 +767,7 @@ void CheckMemoryLeakStructMemberImpl::checkStructVariable(const Variable* const auto deallocInFunction = [this](const Token* tok, int structid) -> bool { // Calling non-function / function that doesn't deallocate? - if (tok->isKeyword() || mSettings->library.isLeakIgnore(tok->str())) + if (tok->isKeyword() || mSettings.library.isLeakIgnore(tok->str())) return false; // Check if the struct is used.. @@ -889,7 +889,7 @@ void CheckMemoryLeakStructMemberImpl::checkStructVariable(const Variable* const } // Deallocating the struct.. - else if (Token::Match(tok3, "%name% ( %varid% )", structid) && mSettings->library.getDeallocFuncInfo(tok3)) { + else if (Token::Match(tok3, "%name% ( %varid% )", structid) && mSettings.library.getDeallocFuncInfo(tok3)) { if (indentlevel2 == 0) memoryLeak(tok3, variable->name() + "." + tok2->strAt(2), allocType); break; @@ -923,7 +923,7 @@ void CheckMemoryLeakStructMemberImpl::checkStructVariable(const Variable* const --indentlevel4; if (indentlevel4 == 0) break; - } else if (Token::Match(tok4, "%name% ( %var% . %varid% )", structmemberid) && mSettings->library.getDeallocFuncInfo(tok4)) { + } else if (Token::Match(tok4, "%name% ( %var% . %varid% )", structmemberid) && mSettings.library.getDeallocFuncInfo(tok4)) { break; } } @@ -968,11 +968,11 @@ void CheckMemoryLeakStructMemberImpl::checkStructVariable(const Variable* const void CheckMemoryLeakStructMember::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckMemoryLeakStructMemberImpl checkMemoryLeak(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckMemoryLeakStructMemberImpl checkMemoryLeak(&tokenizer, tokenizer.getSettings(), errorLogger); checkMemoryLeak.check(); } -void CheckMemoryLeakStructMember::getErrorMessages(ErrorLogger * errorLogger, const Settings * settings) const +void CheckMemoryLeakStructMember::getErrorMessages(ErrorLogger * errorLogger, const Settings & settings) const { (void)errorLogger; (void)settings; @@ -1028,7 +1028,7 @@ void CheckMemoryLeakNoVarImpl::checkForUnreleasedInputArgument(const Scope *scop if (Token::simpleMatch(tok->next()->astParent(), "(")) // passed to another function continue; - if (!tok->isKeyword() && !tok->function() && !mSettings->library.isLeakIgnore(functionName)) + if (!tok->isKeyword() && !tok->function() && !mSettings.library.isLeakIgnore(functionName)) continue; const std::vector args = getArguments(tok); @@ -1048,8 +1048,8 @@ void CheckMemoryLeakNoVarImpl::checkForUnreleasedInputArgument(const Scope *scop if (alloc == New || alloc == NewArray) { const Token* typeTok = arg->next(); bool bail = !typeTok->isStandardType() && - !mSettings->library.detectContainerOrIterator(typeTok) && - !mSettings->library.podtype(typeTok->expressionString()); + !mSettings.library.detectContainerOrIterator(typeTok) && + !mSettings.library.podtype(typeTok->expressionString()); if (bail && typeTok->type() && typeTok->type()->classScope && typeTok->type()->classScope->numConstructors == 0 && typeTok->type()->classScope->getDestructor() == nullptr) { @@ -1064,8 +1064,8 @@ void CheckMemoryLeakNoVarImpl::checkForUnreleasedInputArgument(const Scope *scop const Variable* argvar = tok->function()->getArgumentVar(argnr); if (!argvar || !argvar->valueType()) continue; - const size_t argSize = argvar->valueType()->getSizeOf(*mSettings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointer); - if (argSize == 0 || argSize >= mSettings->platform.sizeof_pointer) + const size_t argSize = argvar->valueType()->getSizeOf(mSettings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointer); + if (argSize == 0 || argSize >= mSettings.platform.sizeof_pointer) continue; } functionCallLeak(arg, arg->str(), functionName); @@ -1110,7 +1110,7 @@ void CheckMemoryLeakNoVarImpl::checkForUnusedReturnValue(const Scope *scope) bool warn = true; if (isNew) { const Token* typeTok = tok->next(); - warn = typeTok && (typeTok->isStandardType() || mSettings->library.detectContainer(typeTok)); + warn = typeTok && (typeTok->isStandardType() || mSettings.library.detectContainer(typeTok)); } if (!parent && warn) { @@ -1150,7 +1150,7 @@ void CheckMemoryLeakNoVarImpl::checkForUnsafeArgAlloc(const Scope *scope) if (!mTokenizer->isCPP()) return; - if (!mSettings->isPremiumEnabled("leakUnsafeArgAlloc") && (!mSettings->certainty.isEnabled(Certainty::inconclusive) || !mSettings->severity.isEnabled(Severity::warning))) + if (!mSettings.isPremiumEnabled("leakUnsafeArgAlloc") && (!mSettings.certainty.isEnabled(Certainty::inconclusive) || !mSettings.severity.isEnabled(Severity::warning))) return; logChecker("CheckMemoryLeakNoVar::checkForUnsafeArgAlloc"); @@ -1216,11 +1216,11 @@ void CheckMemoryLeakNoVarImpl::unsafeArgAllocError(const Token *tok, const std:: void CheckMemoryLeakNoVar::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckMemoryLeakNoVarImpl checkMemoryLeak(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckMemoryLeakNoVarImpl checkMemoryLeak(&tokenizer, tokenizer.getSettings(), errorLogger); checkMemoryLeak.check(); } -void CheckMemoryLeakNoVar::getErrorMessages(ErrorLogger *e, const Settings *settings) const +void CheckMemoryLeakNoVar::getErrorMessages(ErrorLogger *e, const Settings &settings) const { CheckMemoryLeakNoVarImpl c(nullptr, settings, e); c.functionCallLeak(nullptr, "funcName", "funcName"); diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index 047cf3295ae..6c867749fa4 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -75,7 +75,7 @@ class CPPCHECKLIB CheckMemoryLeakInFunction : public Check { void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; /** Report all possible errors (for the --errorlist) */ - void getErrorMessages(ErrorLogger *e, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *e, const Settings &settings) const override; /** * Get class information (--doc) @@ -100,7 +100,7 @@ class CPPCHECKLIB CheckMemoryLeakInClass : public Check { private: void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *e, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *e, const Settings &settings) const override; std::string classInfo() const override { return "If the constructor allocate memory then the destructor must deallocate it.\n"; @@ -120,7 +120,7 @@ class CPPCHECKLIB CheckMemoryLeakStructMember : public Check { private: void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger * errorLogger, const Settings * settings) const override; + void getErrorMessages(ErrorLogger * errorLogger, const Settings & settings) const override; std::string classInfo() const override { return "Don't forget to deallocate struct members\n"; @@ -140,7 +140,7 @@ class CPPCHECKLIB CheckMemoryLeakNoVar : public Check { private: void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *e, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *e, const Settings &settings) const override; std::string classInfo() const override { return "Not taking the address to allocated memory\n"; @@ -175,7 +175,7 @@ class CPPCHECKLIB CheckMemoryLeakImpl : public CheckImpl { CheckMemoryLeakImpl(const CheckMemoryLeakImpl &) = delete; CheckMemoryLeakImpl& operator=(const CheckMemoryLeakImpl &) = delete; - CheckMemoryLeakImpl(const Tokenizer *t, const Settings *s, ErrorLogger *e) + CheckMemoryLeakImpl(const Tokenizer *t, const Settings &s, ErrorLogger *e) : CheckImpl(t, s, e) {} /** @brief What type of allocation are used.. the "Many" means that several types of allocation and deallocation are used */ @@ -254,7 +254,7 @@ class CPPCHECKLIB CheckMemoryLeakImpl : public CheckImpl { class CPPCHECKLIB CheckMemoryLeakInFunctionImpl : public CheckMemoryLeakImpl { public: /** @brief This constructor is used when running checks */ - CheckMemoryLeakInFunctionImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckMemoryLeakInFunctionImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckMemoryLeakImpl(tokenizer, settings, errorLogger) {} /** @@ -271,7 +271,7 @@ class CPPCHECKLIB CheckMemoryLeakInFunctionImpl : public CheckMemoryLeakImpl { class CPPCHECKLIB CheckMemoryLeakInClassImpl : private CheckMemoryLeakImpl { public: - CheckMemoryLeakInClassImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckMemoryLeakInClassImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckMemoryLeakImpl(tokenizer, settings, errorLogger) {} void check(); @@ -292,7 +292,7 @@ class CPPCHECKLIB CheckMemoryLeakInClassImpl : private CheckMemoryLeakImpl { class CPPCHECKLIB CheckMemoryLeakStructMemberImpl : private CheckMemoryLeakImpl { public: - CheckMemoryLeakStructMemberImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckMemoryLeakStructMemberImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckMemoryLeakImpl(tokenizer, settings, errorLogger) {} void check(); @@ -309,7 +309,7 @@ class CPPCHECKLIB CheckMemoryLeakStructMemberImpl : private CheckMemoryLeakImpl class CPPCHECKLIB CheckMemoryLeakNoVarImpl : private CheckMemoryLeakImpl { public: - CheckMemoryLeakNoVarImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckMemoryLeakNoVarImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckMemoryLeakImpl(tokenizer, settings, errorLogger) {} void check(); diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 2dbff296cf0..92938b4a60f 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -130,7 +130,7 @@ namespace { bool CheckNullPointerImpl::isPointerDeRef(const Token *tok, bool &unknown) const { - return isPointerDeRef(tok, unknown, *mSettings); + return isPointerDeRef(tok, unknown, mSettings); } bool CheckNullPointerImpl::isPointerDeRef(const Token *tok, bool &unknown, const Settings &settings, bool checkNullArg) @@ -266,7 +266,7 @@ static bool isNullablePointer(const Token* tok) void CheckNullPointerImpl::nullPointerByDeRefAndCheck() { - const bool printInconclusive = (mSettings->certainty.isEnabled(Certainty::inconclusive)); + const bool printInconclusive = (mSettings.certainty.isEnabled(Certainty::inconclusive)); const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { @@ -292,13 +292,13 @@ void CheckNullPointerImpl::nullPointerByDeRefAndCheck() return true; }; const Token* const start = (scope->function && scope->function->isConstructor()) ? scope->function->token : scope->bodyStart; // Check initialization list - std::vector tokens = findTokensSkipDeadAndUnevaluatedCode(mSettings->library, start, scope->bodyEnd, pred); + std::vector tokens = findTokensSkipDeadAndUnevaluatedCode(mSettings.library, start, scope->bodyEnd, pred); for (const Token *tok : tokens) { const ValueFlow::Value *value = tok->getValue(0); // Pointer dereference. bool unknown = false; - if (!CheckNullPointerImpl::isPointerDeRef(tok, unknown, *mSettings)) { + if (!CheckNullPointerImpl::isPointerDeRef(tok, unknown, mSettings)) { if (unknown) nullPointerError(tok, tok->expressionString(), value, true); continue; @@ -357,7 +357,7 @@ void CheckNullPointerImpl::nullConstantDereference() if (var && !var->isPointer() && !var->isArray() && var->isStlStringType()) nullPointerError(tok); } else { // function call - const std::list var = parseFunctionCall(*tok, mSettings->library); + const std::list var = parseFunctionCall(*tok, mSettings.library); // is one of the var items a NULL pointer? for (const Token *vartok : var) { @@ -376,7 +376,7 @@ void CheckNullPointerImpl::nullConstantDereference() continue; if (argtok->getKnownIntValue() != 0) continue; - if (mSettings->library.isnullargbad(tok, argnr+1)) + if (mSettings.library.isnullargbad(tok, argnr+1)) nullPointerError(argtok); } } @@ -444,7 +444,7 @@ void CheckNullPointerImpl::nullPointerError(const Token *tok, const std::string return; } - if (!mSettings->isEnabled(value, inconclusive) && !mSettings->isPremiumEnabled("nullPointer")) + if (!mSettings.isEnabled(value, inconclusive) && !mSettings.isPremiumEnabled("nullPointer")) return; ErrorPath errorPath = getErrorPath(tok, value, "Null pointer dereference"); @@ -503,9 +503,9 @@ void CheckNullPointerImpl::arithmetic() const ValueFlow::Value* value = pointerOperand->getValue(0); if (!value) continue; - if (!mSettings->certainty.isEnabled(Certainty::inconclusive) && value->isInconclusive()) + if (!mSettings.certainty.isEnabled(Certainty::inconclusive) && value->isInconclusive()) continue; - if (value->condition && !mSettings->severity.isEnabled(Severity::warning)) + if (value->condition && !mSettings.severity.isEnabled(Severity::warning)) continue; if (value->condition) redundantConditionWarning(tok, value, value->condition, value->isInconclusive()); @@ -632,7 +632,7 @@ bool CheckNullPointer::analyseWholeProgram(const CTU::FileInfo &ctu, const std:: { (void)settings; - CheckNullPointerImpl dummy(nullptr, &settings, &errorLogger); + CheckNullPointerImpl dummy(nullptr, settings, &errorLogger); dummy. logChecker("CheckNullPointer::analyseWholeProgram"); @@ -694,13 +694,13 @@ bool CheckNullPointer::analyseWholeProgram(const CTU::FileInfo &ctu, const std:: void CheckNullPointer::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckNullPointerImpl checkNullPointer(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckNullPointerImpl checkNullPointer(&tokenizer, tokenizer.getSettings(), errorLogger); checkNullPointer.nullPointer(); checkNullPointer.arithmetic(); checkNullPointer.nullConstantDereference(); } -void CheckNullPointer::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckNullPointer::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckNullPointerImpl c(nullptr, settings, errorLogger); c.nullPointerError(nullptr, "pointer", nullptr, false); diff --git a/lib/checknullpointer.h b/lib/checknullpointer.h index f9f78280fea..4da9fe8abc7 100644 --- a/lib/checknullpointer.h +++ b/lib/checknullpointer.h @@ -67,7 +67,7 @@ class CPPCHECKLIB CheckNullPointer : public Check { bool analyseWholeProgram(const CTU::FileInfo &ctu, const std::list &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override; /** Get error messages. Used by --errorlist */ - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; /** class info in WIKI format. Used by --doc */ std::string classInfo() const override { @@ -80,7 +80,7 @@ class CPPCHECKLIB CheckNullPointer : public Check { class CPPCHECKLIB CheckNullPointerImpl : public CheckImpl { public: /** @brief This constructor is used when running checks. */ - CheckNullPointerImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckNullPointerImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 6edbef63c0e..1adcaeb9c3a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -82,7 +82,7 @@ static const CWE CWE783(783U); // Operator Precedence Logic Error //---------------------------------------------------------------------------------- void CheckOtherImpl::checkCastIntToCharAndBack() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckOther::checkCastIntToCharAndBack"); // warning @@ -152,7 +152,7 @@ void CheckOtherImpl::checkCastIntToCharAndBackError(const Token *tok, const std: //--------------------------------------------------------------------------- void CheckOtherImpl::clarifyCalculation() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("clarifyCalculation")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("clarifyCalculation")) return; logChecker("CheckOther::clarifyCalculation"); // style @@ -223,7 +223,7 @@ void CheckOtherImpl::clarifyCalculationError(const Token *tok, const std::string //--------------------------------------------------------------------------- void CheckOtherImpl::clarifyStatement() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckOther::clarifyStatement"); // warning @@ -259,7 +259,7 @@ void CheckOtherImpl::clarifyStatementError(const Token *tok) //--------------------------------------------------------------------------- void CheckOtherImpl::checkSuspiciousSemicolon() { - if (!mSettings->certainty.isEnabled(Certainty::inconclusive) || !mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.certainty.isEnabled(Certainty::inconclusive) || !mSettings.severity.isEnabled(Severity::warning)) return; const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase(); @@ -335,7 +335,7 @@ void CheckOtherImpl::warningOldStylePointerCast() if (!mTokenizer->isCPP()) return; - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("cstyleCast")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("cstyleCast")) return; logChecker("CheckOther::warningOldStylePointerCast"); // style,c++ @@ -410,7 +410,7 @@ void CheckOtherImpl::warningDangerousTypeCast() // Only valid on C++ code if (!mTokenizer->isCPP()) return; - if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("dangerousTypeCast")) + if (!mSettings.severity.isEnabled(Severity::warning) && !mSettings.isPremiumEnabled("dangerousTypeCast")) return; logChecker("CheckOther::warningDangerousTypeCast"); // warning,c++ @@ -444,7 +444,7 @@ void CheckOtherImpl::dangerousTypeCastError(const Token *tok, bool isPtr) void CheckOtherImpl::warningIntToPointerCast() { - if (!mSettings->severity.isEnabled(Severity::portability) && !mSettings->isPremiumEnabled("cstyleCast")) + if (!mSettings.severity.isEnabled(Severity::portability) && !mSettings.isPremiumEnabled("cstyleCast")) return; logChecker("CheckOther::warningIntToPointerCast"); // portability @@ -480,7 +480,7 @@ void CheckOtherImpl::intToPointerCastError(const Token *tok, const std::string& void CheckOtherImpl::suspiciousFloatingPointCast() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("suspiciousFloatingPointCast")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("suspiciousFloatingPointCast")) return; logChecker("CheckOther::suspiciousFloatingPointCast"); // style @@ -541,12 +541,12 @@ void CheckOtherImpl::suspiciousFloatingPointCastError(const Token* tok) void CheckOtherImpl::invalidPointerCast() { - if (!mSettings->severity.isEnabled(Severity::portability)) + if (!mSettings.severity.isEnabled(Severity::portability)) return; logChecker("CheckOther::invalidPointerCast"); // portability - const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive); + const bool printInconclusive = mSettings.certainty.isEnabled(Certainty::inconclusive); const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { @@ -594,9 +594,9 @@ void CheckOtherImpl::invalidPointerCastError(const Token* tok, const std::string void CheckOtherImpl::checkRedundantAssignment() { - if (!mSettings->severity.isEnabled(Severity::style) && - !mSettings->isPremiumEnabled("redundantAssignment") && - !mSettings->isPremiumEnabled("redundantAssignInSwitch")) + if (!mSettings.severity.isEnabled(Severity::style) && + !mSettings.isPremiumEnabled("redundantAssignment") && + !mSettings.isPremiumEnabled("redundantAssignInSwitch")) return; logChecker("CheckOther::checkRedundantAssignment"); // style @@ -666,10 +666,10 @@ void CheckOtherImpl::checkRedundantAssignment() if (tok->astOperand1()->valueType()->type == ValueType::SMART_POINTER) break; } - if (inconclusive && !mSettings->certainty.isEnabled(Certainty::inconclusive)) + if (inconclusive && !mSettings.certainty.isEnabled(Certainty::inconclusive)) continue; - FwdAnalysis fwdAnalysis(*mSettings); + FwdAnalysis fwdAnalysis(mSettings); if (fwdAnalysis.hasOperand(tok->astOperand2(), tok->astOperand1())) continue; @@ -794,7 +794,7 @@ static inline bool isFunctionOrBreakPattern(const Token *tok) void CheckOtherImpl::redundantBitwiseOperationInSwitchError() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckOther::redundantBitwiseOperationInSwitch"); // warning @@ -923,7 +923,7 @@ void CheckOtherImpl::redundantBitwiseOperationInSwitchError(const Token *tok, co //--------------------------------------------------------------------------- void CheckOtherImpl::checkSuspiciousCaseInSwitch() { - if (!mSettings->certainty.isEnabled(Certainty::inconclusive) || !mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.certainty.isEnabled(Certainty::inconclusive) || !mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckOther::checkSuspiciousCaseInSwitch"); // warning,inconclusive @@ -1011,12 +1011,12 @@ void CheckOtherImpl::checkUnreachableCode() // misra-c-2023-2.1 // misra-cpp-2008-0-1-1 // autosar - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("duplicateBreak") && !mSettings->isPremiumEnabled("unreachableCode")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("duplicateBreak") && !mSettings.isPremiumEnabled("unreachableCode")) return; logChecker("CheckOther::checkUnreachableCode"); // style - const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive); + const bool printInconclusive = mSettings.certainty.isEnabled(Certainty::inconclusive); const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { if (scope->hasInlineOrLambdaFunction(nullptr, /*onlyInline*/ true)) @@ -1043,7 +1043,7 @@ void CheckOtherImpl::checkUnreachableCode() } else if (Token::Match(tok, "goto %any% ;")) { secondBreak = tok->tokAt(3); labelName = tok->next(); - } else if (Token::Match(tok, "%name% (") && mSettings->library.isnoreturn(tok) && !Token::Match(tok->next()->astParent(), "?|:")) { + } else if (Token::Match(tok, "%name% (") && mSettings.library.isnoreturn(tok) && !Token::Match(tok->next()->astParent(), "?|:")) { if ((!tok->function() || (tok->function()->token != tok && tok->function()->tokenDef != tok)) && tok->linkAt(1)->strAt(1) != "{") secondBreak = tok->linkAt(1)->tokAt(2); if (Token::simpleMatch(secondBreak, "return")) { @@ -1136,7 +1136,7 @@ void CheckOtherImpl::duplicateBreakError(const Token *tok, bool inconclusive) void CheckOtherImpl::unreachableCodeError(const Token *tok, const Token* noreturn, bool inconclusive) { std::string msg = "Statements following "; - if (noreturn && (noreturn->function() || mSettings->library.isnoreturn(noreturn))) + if (noreturn && (noreturn->function() || mSettings.library.isnoreturn(noreturn))) msg += "noreturn function '" + noreturn->str() + "()'"; else if (noreturn && noreturn->isKeyword()) msg += "'" + noreturn->str() + "'"; @@ -1185,17 +1185,17 @@ static bool isSimpleExpr(const Token* tok, const Variable* var, const Settings& //--------------------------------------------------------------------------- void CheckOtherImpl::checkVariableScope() { - if (mSettings->clang) + if (mSettings.clang) return; - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("variableScope")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("variableScope")) return; const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); // In C it is common practice to declare local variables at the // start of functions. - if (mSettings->daca && mTokenizer->isC()) + if (mSettings.daca && mTokenizer->isC()) return; logChecker("CheckOther::checkVariableScope"); // style,notclang @@ -1244,7 +1244,7 @@ void CheckOtherImpl::checkVariableScope() bool isConstructor = false; if (Token::Match(tok, "; %varid% =", var->declarationId())) { // bailout for assignment tok = tok->tokAt(2)->astOperand2(); - if (!isSimpleExpr(tok, var, *mSettings)) + if (!isSimpleExpr(tok, var, mSettings)) continue; } else if (Token::Match(tok, "{|(")) { // bailout for constructor @@ -1253,11 +1253,11 @@ void CheckOtherImpl::checkVariableScope() bool bail = false; while (argTok) { if (Token::simpleMatch(argTok, ",")) { - if (!isSimpleExpr(argTok->astOperand2(), var, *mSettings)) { + if (!isSimpleExpr(argTok->astOperand2(), var, mSettings)) { bail = true; break; } - } else if (argTok->str() != "." && !isSimpleExpr(argTok, var, *mSettings)) { + } else if (argTok->str() != "." && !isSimpleExpr(argTok, var, mSettings)) { bail = true; break; } @@ -1422,7 +1422,7 @@ bool CheckOtherImpl::checkInnerScope(const Token *tok, const Variable* var, bool if (ftok->next()->astParent()) { // return value used? if (ftok->function() && Function::returnsPointer(ftok->function())) return false; - const std::string ret = mSettings->library.returnValueType(ftok); // assume that var is returned + const std::string ret = mSettings.library.returnValueType(ftok); // assume that var is returned if (!ret.empty() && ret.back() == '*') return false; } @@ -1437,7 +1437,7 @@ bool CheckOtherImpl::checkInnerScope(const Token *tok, const Variable* var, bool } } } - const auto yield = astContainerYield(tok, mSettings->library); + const auto yield = astContainerYield(tok, mSettings.library); if (yield == Library::Container::Yield::BUFFER || yield == Library::Container::Yield::BUFFER_NT) return false; } @@ -1476,7 +1476,7 @@ void CheckOtherImpl::variableScopeError(const Token *tok, const std::string &var void CheckOtherImpl::checkCommaSeparatedReturn() { // TODO: This is experimental for now. See #5076 - if ((true) || !mSettings->severity.isEnabled(Severity::style)) // NOLINT(readability-simplify-boolean-expr,readability-redundant-parentheses) + if ((true) || !mSettings.severity.isEnabled(Severity::style)) // NOLINT(readability-simplify-boolean-expr,readability-redundant-parentheses) return; // logChecker @@ -1540,7 +1540,7 @@ static bool isLargeContainer(const Variable* var, const Settings& settings) void CheckOtherImpl::checkPassByReference() { - if (!mSettings->severity.isEnabled(Severity::performance) || mTokenizer->isC()) + if (!mSettings.severity.isEnabled(Severity::performance) || mTokenizer->isC()) return; logChecker("CheckOther::checkPassByReference"); // performance,c++ @@ -1566,21 +1566,21 @@ void CheckOtherImpl::checkPassByReference() bool inconclusive = false; const bool isContainer = var->valueType() && var->valueType()->type == ValueType::Type::CONTAINER && var->valueType()->container && !var->valueType()->container->view; - if (isContainer && !isLargeContainer(var, *mSettings)) + if (isContainer && !isLargeContainer(var, mSettings)) continue; if (!isContainer) { if (var->type() && !var->type()->isEnumType()) { // Check if type is a struct or class. // Ensure that it is a large object. if (!var->type()->classScope) inconclusive = true; - else if (!var->valueType() || var->valueType()->getSizeOf(*mSettings, ValueType::Accuracy::LowerBound, ValueType::SizeOf::Pointer) <= 2 * mSettings->platform.sizeof_pointer) + else if (!var->valueType() || var->valueType()->getSizeOf(mSettings, ValueType::Accuracy::LowerBound, ValueType::SizeOf::Pointer) <= 2 * mSettings.platform.sizeof_pointer) continue; } else continue; } - if (inconclusive && !mSettings->certainty.isEnabled(Certainty::inconclusive)) + if (inconclusive && !mSettings.certainty.isEnabled(Certainty::inconclusive)) continue; if (var->isArray() && (!var->isStlType() || Token::simpleMatch(var->nameToken()->next(), "["))) @@ -1611,7 +1611,7 @@ void CheckOtherImpl::checkPassByReference() if (!isRangeBasedFor && (!var->scope() || var->scope()->function->isImplicitlyVirtual())) continue; - if (!isVariableChanged(var, *mSettings)) { + if (!isVariableChanged(var, mSettings)) { passedByValueError(var, inconclusive, isRangeBasedFor); } } @@ -1684,7 +1684,7 @@ static bool isCastToVoid(const Variable* var) void CheckOtherImpl::checkConstVariable() { - if ((!mSettings->severity.isEnabled(Severity::style) || mTokenizer->isC()) && !mSettings->isPremiumEnabled("constVariable")) + if ((!mSettings.severity.isEnabled(Severity::style) || mTokenizer->isC()) && !mSettings.isPremiumEnabled("constVariable")) return; logChecker("CheckOther::checkConstVariable"); // style,c++ @@ -1732,7 +1732,7 @@ void CheckOtherImpl::checkConstVariable() continue; if (isCastToVoid(var)) continue; - if (isVariableChanged(var, *mSettings)) + if (isVariableChanged(var, mSettings)) continue; const bool hasFunction = function != nullptr; if (!hasFunction) { @@ -1755,7 +1755,7 @@ void CheckOtherImpl::checkConstVariable() ValueFlow::Value ltVal = ValueFlow::getLifetimeObjValue(retTok); if (ltVal.isLifetimeValue() && ltVal.tokvalue->varId() == var->declarationId()) return true; - return ValueFlow::hasLifetimeToken(getParentLifetime(retTok), var->nameToken(), *mSettings); + return ValueFlow::hasLifetimeToken(getParentLifetime(retTok), var->nameToken(), mSettings); })) continue; } @@ -1791,7 +1791,7 @@ void CheckOtherImpl::checkConstVariable() continue; } else if (const Token* ftok = getTokenArgumentFunction(tok, argn)) { bool inconclusive{}; - if (var->valueType() && !isVariableChangedByFunctionCall(ftok, var->valueType()->pointer, var->declarationId(), *mSettings, &inconclusive) && !inconclusive) + if (var->valueType() && !isVariableChangedByFunctionCall(ftok, var->valueType()->pointer, var->declarationId(), mSettings, &inconclusive) && !inconclusive) continue; } usedInAssignment = true; @@ -1877,11 +1877,11 @@ static const Function* getEnclosingFunction(const Variable* var) void CheckOtherImpl::checkConstPointer() { - if (!mSettings->severity.isEnabled(Severity::style) && - !mSettings->isPremiumEnabled("constParameter") && - !mSettings->isPremiumEnabled("constParameterPointer") && - !mSettings->isPremiumEnabled("constParameterReference") && - !mSettings->isPremiumEnabled("constVariablePointer")) + if (!mSettings.severity.isEnabled(Severity::style) && + !mSettings.isPremiumEnabled("constParameter") && + !mSettings.isPremiumEnabled("constParameterPointer") && + !mSettings.isPremiumEnabled("constParameterReference") && + !mSettings.isPremiumEnabled("constVariablePointer")) return; logChecker("CheckOther::checkConstPointer"); // style @@ -1946,7 +1946,7 @@ void CheckOtherImpl::checkConstPointer() if (parent->astOperand2()) { if (parent->astOperand2()->function() && parent->astOperand2()->function()->isConst()) continue; - if (mSettings->library.isFunctionConst(parent->astOperand2())) + if (mSettings.library.isFunctionConst(parent->astOperand2())) continue; if (parent->astOperand2()->varId()) { if (gparent->str() == "?" && astIsLHS(parent)) @@ -1984,7 +1984,7 @@ void CheckOtherImpl::checkConstPointer() continue; else if (const Token* ftok = getTokenArgumentFunction(parent, argn)) { bool inconclusive{}; - if (!isVariableChangedByFunctionCall(ftok->next(), vt->pointer, var->declarationId(), *mSettings, &inconclusive) && !inconclusive) + if (!isVariableChangedByFunctionCall(ftok->next(), vt->pointer, var->declarationId(), mSettings, &inconclusive) && !inconclusive) continue; } } else { @@ -2009,12 +2009,12 @@ void CheckOtherImpl::checkConstPointer() const Variable* argVar = ftok->function()->getArgumentVar(argn); if (argVar && argVar->valueType() && argVar->valueType()->isConst(vt->pointer)) { bool inconclusive{}; - if (!isVariableChangedByFunctionCall(ftok, vt->pointer, var->declarationId(), *mSettings, &inconclusive) && !inconclusive) + if (!isVariableChangedByFunctionCall(ftok, vt->pointer, var->declarationId(), mSettings, &inconclusive) && !inconclusive) continue; } } } else { - const auto dir = mSettings->library.getArgDirection(ftok, argn + 1); + const auto dir = mSettings.library.getArgDirection(ftok, argn + 1); if (dir == Library::ArgumentChecks::Direction::DIR_IN) continue; } @@ -2042,7 +2042,7 @@ void CheckOtherImpl::checkConstPointer() // const int indirect = p->isArray() ? p->dimensions().size() : 1; // if (isVariableChanged(start, p->scope()->bodyEnd, indirect, p->declarationId(), false, *mSettings)) // continue; - if (!isConstPointerVariable(p, *mSettings)) + if (!isConstPointerVariable(p, mSettings)) continue; if (p->typeStartToken() && p->typeStartToken()->isSimplifiedTypedef() && !(Token::simpleMatch(p->typeEndToken(), "*") && !p->typeEndToken()->isSimplifiedTypedef())) continue; @@ -2091,8 +2091,8 @@ void CheckOtherImpl::constVariableError(const Variable *var, const Function *fun void CheckOtherImpl::checkCharVariable() { - const bool warning = mSettings->severity.isEnabled(Severity::warning); - const bool portability = mSettings->severity.isEnabled(Severity::portability); + const bool warning = mSettings.severity.isEnabled(Severity::warning); + const bool portability = mSettings.severity.isEnabled(Severity::portability); if (!warning && !portability) return; @@ -2107,24 +2107,24 @@ void CheckOtherImpl::checkCharVariable() if (!tok->variable()->isArray() && !tok->variable()->isPointer()) continue; const Token *index = tok->next()->astOperand2(); - if (warning && tok->variable()->isArray() && astIsSignedChar(index) && index->getValueGE(0x80, *mSettings)) + if (warning && tok->variable()->isArray() && astIsSignedChar(index) && index->getValueGE(0x80, mSettings)) signedCharArrayIndexError(tok); - if (portability && astIsUnknownSignChar(index) && index->getValueGE(0x80, *mSettings)) + if (portability && astIsUnknownSignChar(index) && index->getValueGE(0x80, mSettings)) unknownSignCharArrayIndexError(tok); } else if (warning && Token::Match(tok, "[&|^]") && tok->isBinaryOp()) { bool warn = false; if (astIsSignedChar(tok->astOperand1())) { - const ValueFlow::Value *v1 = tok->astOperand1()->getValueLE(-1, *mSettings); + const ValueFlow::Value *v1 = tok->astOperand1()->getValueLE(-1, mSettings); const ValueFlow::Value *v2 = tok->astOperand2()->getMaxValue(false); if (!v1) - v1 = tok->astOperand1()->getValueGE(0x80, *mSettings); + v1 = tok->astOperand1()->getValueGE(0x80, mSettings); if (v1 && !(tok->str() == "&" && v2 && v2->isKnown() && v2->intvalue >= 0 && v2->intvalue < 0x100)) warn = true; } else if (astIsSignedChar(tok->astOperand2())) { - const ValueFlow::Value *v1 = tok->astOperand2()->getValueLE(-1, *mSettings); + const ValueFlow::Value *v1 = tok->astOperand2()->getValueLE(-1, mSettings); const ValueFlow::Value *v2 = tok->astOperand1()->getMaxValue(false); if (!v1) - v1 = tok->astOperand2()->getValueGE(0x80, *mSettings); + v1 = tok->astOperand2()->getValueGE(0x80, mSettings); if (v1 && !(tok->str() == "&" && v2 && v2->isKnown() && v2->intvalue >= 0 && v2->intvalue < 0x100)) warn = true; } @@ -2350,8 +2350,8 @@ static bool isConstTop(const Token *tok) void CheckOtherImpl::checkIncompleteStatement() { - if (!mSettings->severity.isEnabled(Severity::warning) && - !mSettings->isPremiumEnabled("constStatement")) + if (!mSettings.severity.isEnabled(Severity::warning) && + !mSettings.isPremiumEnabled("constStatement")) return; logChecker("CheckOther::checkIncompleteStatement"); // warning @@ -2397,15 +2397,15 @@ void CheckOtherImpl::checkIncompleteStatement() // Skip statement expressions if (Token::simpleMatch(rtok, "; } )")) continue; - if (!isConstStatement(tok, mSettings->library, false)) + if (!isConstStatement(tok, mSettings.library, false)) continue; if (isVoidStmt(tok)) continue; if (tok->isCpp() && tok->str() == "&" && !(tok->astOperand1() && tok->astOperand1()->valueType() && tok->astOperand1()->valueType()->isIntegral())) // Possible archive continue; - const bool inconclusive = tok->isConstOp() && !mSettings->isPremiumEnabled("constStatement"); - if (mSettings->certainty.isEnabled(Certainty::inconclusive) || !inconclusive) + const bool inconclusive = tok->isConstOp() && !mSettings.isPremiumEnabled("constStatement"); + if (mSettings.certainty.isEnabled(Certainty::inconclusive) || !inconclusive) constStatementError(tok, tok->isNumber() ? "numeric" : "string", inconclusive); } } @@ -2455,7 +2455,7 @@ void CheckOtherImpl::constStatementError(const Token *tok, const std::string &ty msg = "Redundant code: Found unused function."; else if (Token::Match(tok->previous(), "%name% (")) msg = "Redundant code: Found unused '" + tok->strAt(-1) + "' expression."; - else if (mSettings->debugwarnings) { + else if (mSettings.debugwarnings) { reportError(tok, Severity::debug, "debug", "constStatementError not handled."); return; } @@ -2481,7 +2481,7 @@ void CheckOtherImpl::checkZeroDivision() // Value flow.. const ValueFlow::Value *value = tok->astOperand2()->getValue(0LL); - if (value && mSettings->isEnabled(value, false)) + if (value && mSettings.isEnabled(value, false)) zerodivError(tok, value); } } @@ -2517,7 +2517,7 @@ void CheckOtherImpl::zerodivError(const Token *tok, const ValueFlow::Value *valu void CheckOtherImpl::checkNanInArithmeticExpression() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("nanInArithmeticExpression")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("nanInArithmeticExpression")) return; logChecker("CheckOther::checkNanInArithmeticExpression"); // style for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) { @@ -2547,7 +2547,7 @@ void CheckOtherImpl::checkMisusedScopedObject() if (mTokenizer->isC()) return; - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("unusedScopedObject")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("unusedScopedObject")) return; logChecker("CheckOther::checkMisusedScopedObject"); // style,c++ @@ -2574,10 +2574,10 @@ void CheckOtherImpl::checkMisusedScopedObject() }; auto isLibraryConstructor = [&](const Token* tok, const std::string& typeStr) -> bool { - const Library::TypeCheck typeCheck = mSettings->library.getTypeCheck("unusedvar", typeStr); + const Library::TypeCheck typeCheck = mSettings.library.getTypeCheck("unusedvar", typeStr); if (typeCheck == Library::TypeCheck::check || typeCheck == Library::TypeCheck::checkFiniteLifetime) return true; - return mSettings->library.detectContainerOrIterator(tok); + return mSettings.library.detectContainerOrIterator(tok); }; const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase(); @@ -2592,7 +2592,7 @@ void CheckOtherImpl::checkMisusedScopedObject() if (Token::simpleMatch(parTok, "<") && parTok->link()) parTok = parTok->link()->next(); if (const Token* arg = parTok->astOperand2()) { - if (!isConstStatement(arg, mSettings->library, false)) + if (!isConstStatement(arg, mSettings.library, false)) continue; if (parTok->str() == "(") { if (arg->varId() && !(arg->variable() && arg->variable()->nameToken() != arg)) @@ -2651,7 +2651,7 @@ void CheckOtherImpl::checkDuplicateBranch() // and their conditional code is a duplicate of the condition that // is always true just in case it would be false. See for instance // abiword. - if (!mSettings->severity.isEnabled(Severity::style) || !mSettings->certainty.isEnabled(Certainty::inconclusive)) + if (!mSettings.severity.isEnabled(Severity::style) || !mSettings.certainty.isEnabled(Certainty::inconclusive)) return; logChecker("CheckOther::checkDuplicateBranch"); // style,inconclusive @@ -2713,8 +2713,8 @@ void CheckOtherImpl::checkDuplicateBranch() if (branchTop1->str() != branchTop2->str()) continue; ErrorPath errorPath; - if (isSameExpression(false, branchTop1->astOperand1(), branchTop2->astOperand1(), *mSettings, true, true, &errorPath) && - isSameExpression(false, branchTop1->astOperand2(), branchTop2->astOperand2(), *mSettings, true, true, &errorPath)) + if (isSameExpression(false, branchTop1->astOperand1(), branchTop2->astOperand1(), mSettings, true, true, &errorPath) && + isSameExpression(false, branchTop1->astOperand2(), branchTop2->astOperand2(), mSettings, true, true, &errorPath)) duplicateBranchError(scope.classDef, scope.bodyEnd->next(), std::move(errorPath)); } } @@ -2744,14 +2744,14 @@ void CheckOtherImpl::checkInvalidFree() logChecker("CheckOther::checkInvalidFree"); - const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive); + const bool printInconclusive = mSettings.certainty.isEnabled(Certainty::inconclusive); const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { for (const Token* tok = scope->bodyStart->next(); tok && tok != scope->bodyEnd; tok = tok->next()) { // Keep track of which variables were assigned addresses to newly-allocated memory if ((tok->isCpp() && Token::Match(tok, "%var% = new")) || - (Token::Match(tok, "%var% = %name% (") && mSettings->library.getAllocFuncInfo(tok->tokAt(2)))) { + (Token::Match(tok, "%var% = %name% (") && mSettings.library.getAllocFuncInfo(tok->tokAt(2)))) { allocation.emplace(tok->varId(), tok->strAt(2)); inconclusive.emplace(tok->varId(), false); } @@ -2779,7 +2779,7 @@ void CheckOtherImpl::checkInvalidFree() // If a variable that was previously assigned a newly-allocated memory location is // added or subtracted from when used to free the memory, report an error. - else if ((Token::Match(tok, "%name% ( %any% +|-") && mSettings->library.getDeallocFuncInfo(tok)) || + else if ((Token::Match(tok, "%name% ( %any% +|-") && mSettings.library.getDeallocFuncInfo(tok)) || Token::Match(tok, "delete [ ] ( %any% +|-") || Token::Match(tok, "delete %any% +|- %any%")) { @@ -2799,7 +2799,7 @@ void CheckOtherImpl::checkInvalidFree() // If the previously-allocated variable is passed in to another function // as a parameter, it might be modified, so we shouldn't report an error // if it is later used to free memory - else if (Token::Match(tok, "%name% (") && !mSettings->library.isFunctionConst(tok->str(), true)) { + else if (Token::Match(tok, "%name% (") && !mSettings.library.isFunctionConst(tok->str(), true)) { const Token* tok2 = Token::findmatch(tok->next(), "%var%", tok->linkAt(1)); while (tok2 != nullptr) { allocation.erase(tok->varId()); @@ -2873,14 +2873,14 @@ isStaticAssert(const Settings &settings, const Token *tok) void CheckOtherImpl::checkDuplicateExpression() { { - const bool styleEnabled = mSettings->severity.isEnabled(Severity::style); - const bool premiumEnabled = mSettings->isPremiumEnabled("oppositeExpression") || - mSettings->isPremiumEnabled("duplicateExpression") || - mSettings->isPremiumEnabled("duplicateAssignExpression") || - mSettings->isPremiumEnabled("duplicateExpressionTernary") || - mSettings->isPremiumEnabled("duplicateValueTernary") || - mSettings->isPremiumEnabled("selfAssignment") || - mSettings->isPremiumEnabled("knownConditionTrueFalse"); + const bool styleEnabled = mSettings.severity.isEnabled(Severity::style); + const bool premiumEnabled = mSettings.isPremiumEnabled("oppositeExpression") || + mSettings.isPremiumEnabled("duplicateExpression") || + mSettings.isPremiumEnabled("duplicateAssignExpression") || + mSettings.isPremiumEnabled("duplicateExpressionTernary") || + mSettings.isPremiumEnabled("duplicateValueTernary") || + mSettings.isPremiumEnabled("selfAssignment") || + mSettings.isPremiumEnabled("knownConditionTrueFalse"); if (!styleEnabled && !premiumEnabled) return; @@ -2918,8 +2918,8 @@ void CheckOtherImpl::checkDuplicateExpression() Token::Match(tok->astOperand2()->previous(), "%name% (") ) && tok->next()->tokType() != Token::eType && - isSameExpression(true, tok->next(), nextAssign->next(), *mSettings, true, false) && - isSameExpression(true, tok->astOperand2(), nextAssign->astOperand2(), *mSettings, true, false) && + isSameExpression(true, tok->next(), nextAssign->next(), mSettings, true, false) && + isSameExpression(true, tok->astOperand2(), nextAssign->astOperand2(), mSettings, true, false) && tok->astOperand2()->expressionString() == nextAssign->astOperand2()->expressionString()) { bool differentDomain = false; const Scope * varScope = var1->scope() ? var1->scope() : scope; @@ -2937,7 +2937,7 @@ void CheckOtherImpl::checkDuplicateExpression() !isSameExpression(true, tok->astOperand2(), assignTok->astOperand1(), - *mSettings, + mSettings, true, true)) continue; @@ -2946,7 +2946,7 @@ void CheckOtherImpl::checkDuplicateExpression() !isSameExpression(true, tok->astOperand2(), assignTok->astOperand2(), - *mSettings, + mSettings, true, true)) continue; @@ -2955,7 +2955,7 @@ void CheckOtherImpl::checkDuplicateExpression() } if (!differentDomain && !isUniqueExpression(tok->astOperand2())) duplicateAssignExpressionError(var1, var2, false); - else if (mSettings->certainty.isEnabled(Certainty::inconclusive)) { + else if (mSettings.certainty.isEnabled(Certainty::inconclusive)) { diag(assignTok); duplicateAssignExpressionError(var1, var2, true); } @@ -2981,14 +2981,14 @@ void CheckOtherImpl::checkDuplicateExpression() if (isSameExpression(true, tok->astOperand1(), tok->astOperand2(), - *mSettings, + mSettings, true, followVar, &errorPath)) { if (isWithoutSideEffects(tok->astOperand1())) { const Token* loopTok = isInLoopCondition(tok); if (!loopTok || - !findExpressionChanged(tok, tok, loopTok->link()->linkAt(1), *mSettings)) { + !findExpressionChanged(tok, tok, loopTok->link()->linkAt(1), mSettings)) { const bool isEnum = tok->scope()->type == ScopeType::eEnum; const bool assignment = !isEnum && tok->str() == "="; if (assignment) @@ -3000,7 +3000,7 @@ void CheckOtherImpl::checkDuplicateExpression() parent = parent->astParent(); } if (parent && parent->previous() && - (isStaticAssert(*mSettings, parent->previous()) || + (isStaticAssert(mSettings, parent->previous()) || Token::simpleMatch(parent->previous(), "assert"))) { continue; } @@ -3013,7 +3013,7 @@ void CheckOtherImpl::checkDuplicateExpression() isSameExpression(false, tok->astOperand1(), tok->astOperand2()->astOperand1(), - *mSettings, + mSettings, true, false)) { if (isWithoutSideEffects(tok->astOperand1())) { @@ -3021,7 +3021,7 @@ void CheckOtherImpl::checkDuplicateExpression() } } else if (isOppositeExpression(tok->astOperand1(), tok->astOperand2(), - *mSettings, + mSettings, false, true, &errorPath) && @@ -3033,15 +3033,15 @@ void CheckOtherImpl::checkDuplicateExpression() isSameExpression(true, tok->astOperand2(), tok->astOperand1()->astOperand2(), - *mSettings, + mSettings, true, followVar, &errorPath) && isWithoutSideEffects(tok->astOperand2())) duplicateExpressionError(tok->astOperand2(), tok->astOperand1()->astOperand2(), tok, std::move(errorPath)); - else if (tok->astOperand2() && isConstExpression(tok->astOperand1(), mSettings->library)) { + else if (tok->astOperand2() && isConstExpression(tok->astOperand1(), mSettings.library)) { auto checkDuplicate = [&](const Token* exp1, const Token* exp2, const Token* ast1) { - if (isSameExpression(true, exp1, exp2, *mSettings, true, true, &errorPath) && + if (isSameExpression(true, exp1, exp2, mSettings, true, true, &errorPath) && isWithoutSideEffects(exp1) && isWithoutSideEffects(ast1->astOperand2())) duplicateExpressionError(exp1, exp2, tok, errorPath, /*hasMultipleExpr*/ true); @@ -3056,12 +3056,12 @@ void CheckOtherImpl::checkDuplicateExpression() } } } else if (tok->astOperand1() && tok->astOperand2() && tok->str() == ":" && tok->astParent() && tok->astParent()->str() == "?") { - if (isSameExpression(true, tok->astOperand1(), tok->astOperand2(), *mSettings, false, true, &errorPath)) + if (isSameExpression(true, tok->astOperand1(), tok->astOperand2(), mSettings, false, true, &errorPath)) duplicateExpressionTernaryError(tok, std::move(errorPath)); else if (!tok->astOperand1()->values().empty() && !tok->astOperand2()->values().empty() && isEqualKnownValue(tok->astOperand1(), tok->astOperand2()) && - !isVariableChanged(tok->astParent(), /*indirect*/ 0, *mSettings) && - isConstStatement(tok->astOperand1(), mSettings->library, true) && isConstStatement(tok->astOperand2(), mSettings->library, true)) + !isVariableChanged(tok->astParent(), /*indirect*/ 0, mSettings) && + isConstStatement(tok->astOperand1(), mSettings.library, true) && isConstStatement(tok->astOperand2(), mSettings.library, true)) duplicateValueTernaryError(tok); } } @@ -3156,7 +3156,7 @@ void CheckOtherImpl::selfAssignmentError(const Token *tok, const std::string &va //----------------------------------------------------------------------------- void CheckOtherImpl::checkComparisonFunctionIsAlwaysTrueOrFalse() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckOther::checkComparisonFunctionIsAlwaysTrueOrFalse"); // warning @@ -3201,7 +3201,7 @@ void CheckOtherImpl::checkComparisonFunctionIsAlwaysTrueOrFalseError(const Token //--------------------------------------------------------------------------- void CheckOtherImpl::checkSignOfUnsignedVariable() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("unsignedLessThanZero")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("unsignedLessThanZero")) return; logChecker("CheckOther::checkSignOfUnsignedVariable"); // style @@ -3385,7 +3385,7 @@ static bool checkVariableAssignment(const Token* tok, const ValueType* vtLhs, co void CheckOtherImpl::checkRedundantCopy() { - if (!mSettings->severity.isEnabled(Severity::performance) || mTokenizer->isC() || !mSettings->certainty.isEnabled(Certainty::inconclusive)) + if (!mSettings.severity.isEnabled(Severity::performance) || mTokenizer->isC() || !mSettings.certainty.isEnabled(Certainty::inconclusive)) return; logChecker("CheckOther::checkRedundantCopy"); // c++,performance,inconclusive @@ -3395,7 +3395,7 @@ void CheckOtherImpl::checkRedundantCopy() for (const Variable* var : symbolDatabase->variableList()) { if (!var || var->isReference() || var->isPointer() || (!var->type() && !var->isStlType() && !(var->valueType() && var->valueType()->container)) || // bailout if var is of standard type, if it is a pointer or non-const - (!var->isConst() && isVariableChanged(var, *mSettings))) + (!var->isConst() && isVariableChanged(var, mSettings))) continue; const Token* startTok = var->nameToken(); @@ -3415,7 +3415,7 @@ void CheckOtherImpl::checkRedundantCopy() const Token* tok = startTok->next()->astOperand2(); if (!tok) continue; - if (!checkFunctionReturnsRef(tok, *mSettings) && !checkVariableAssignment(tok, var->valueType(), *mSettings)) + if (!checkFunctionReturnsRef(tok, mSettings) && !checkVariableAssignment(tok, var->valueType(), mSettings)) continue; redundantCopyError(startTok, startTok->str()); } @@ -3443,7 +3443,7 @@ static bool isNegative(const Token *tok, const Settings &settings) void CheckOtherImpl::checkNegativeBitwiseShift() { - const bool portability = mSettings->severity.isEnabled(Severity::portability); + const bool portability = mSettings.severity.isEnabled(Severity::portability); logChecker("CheckOther::checkNegativeBitwiseShift"); @@ -3475,9 +3475,9 @@ void CheckOtherImpl::checkNegativeBitwiseShift() continue; // Get negative rhs value. preferably a value which doesn't have 'condition'. - if (portability && isNegative(tok->astOperand1(), *mSettings)) + if (portability && isNegative(tok->astOperand1(), mSettings)) negativeBitwiseShiftError(tok, 1); - else if (isNegative(tok->astOperand2(), *mSettings)) + else if (isNegative(tok->astOperand2(), mSettings)) negativeBitwiseShiftError(tok, 2); } } @@ -3499,10 +3499,10 @@ void CheckOtherImpl::negativeBitwiseShiftError(const Token *tok, int op) //--------------------------------------------------------------------------- void CheckOtherImpl::checkIncompleteArrayFill() { - if (!mSettings->certainty.isEnabled(Certainty::inconclusive)) + if (!mSettings.certainty.isEnabled(Certainty::inconclusive)) return; - const bool printWarning = mSettings->severity.isEnabled(Severity::warning); - const bool printPortability = mSettings->severity.isEnabled(Severity::portability); + const bool printWarning = mSettings.severity.isEnabled(Severity::warning); + const bool printPortability = mSettings.severity.isEnabled(Severity::portability); if (!printPortability && !printWarning) return; @@ -3532,9 +3532,9 @@ void CheckOtherImpl::checkIncompleteArrayFill() continue; int size = mTokenizer->sizeOfType(var->typeStartToken()); if (size == 0 && var->valueType()->pointer) - size = mSettings->platform.sizeof_pointer; + size = mSettings.platform.sizeof_pointer; else if (size == 0 && var->valueType()) - size = var->valueType()->getSizeOf(*mSettings, ValueType::Accuracy::LowerBound, ValueType::SizeOf::Pointer); + size = var->valueType()->getSizeOf(mSettings, ValueType::Accuracy::LowerBound, ValueType::SizeOf::Pointer); const Token* tok3 = tok->next()->astOperand2()->astOperand1()->astOperand1(); if ((size != 1 && size != 100 && size != 0) || var->isPointer()) { if (printWarning) @@ -3568,7 +3568,7 @@ void CheckOtherImpl::incompleteArrayFillError(const Token* tok, const std::strin void CheckOtherImpl::checkVarFuncNullUB() { - if (!mSettings->severity.isEnabled(Severity::portability)) + if (!mSettings.severity.isEnabled(Severity::portability)) return; logChecker("CheckOther::checkVarFuncNullUB"); // portability @@ -3653,7 +3653,7 @@ void CheckOtherImpl::varFuncNullUBError(const Token *tok) void CheckOtherImpl::checkRedundantPointerOp() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("redundantPointerOp")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("redundantPointerOp")) return; logChecker("CheckOther::checkRedundantPointerOp"); // style @@ -3699,7 +3699,7 @@ void CheckOtherImpl::redundantPointerOpError(const Token* tok, const std::string void CheckOtherImpl::checkInterlockedDecrement() { - if (!mSettings->platform.isWindows()) { + if (!mSettings.platform.isWindows()) { return; } @@ -3745,7 +3745,7 @@ void CheckOtherImpl::raceAfterInterlockedDecrementError(const Token* tok) void CheckOtherImpl::checkUnusedLabel() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("unusedLabel")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.severity.isEnabled(Severity::warning) && !mSettings.isPremiumEnabled("unusedLabel")) return; logChecker("CheckOther::checkUnusedLabel"); // style,warning @@ -3768,7 +3768,7 @@ void CheckOtherImpl::checkUnusedLabel() void CheckOtherImpl::unusedLabelError(const Token* tok, bool inSwitch, bool hasIfdef) { - if (tok && !mSettings->severity.isEnabled(inSwitch ? Severity::warning : Severity::style) && !mSettings->isPremiumEnabled("unusedLabel")) + if (tok && !mSettings.severity.isEnabled(inSwitch ? Severity::warning : Severity::style) && !mSettings.isPremiumEnabled("unusedLabel")) return; std::string id = "unusedLabel"; @@ -3900,14 +3900,14 @@ void CheckOtherImpl::checkEvaluationOrder() break; bool foundError{false}, foundUnspecified{false}, bSelfAssignmentError{false}; - if (mTokenizer->isCPP() && mSettings->standards.cpp >= Standards::CPP11) { - if (mSettings->standards.cpp >= Standards::CPP17) - foundError = checkEvaluationOrderCpp17(tok, tok2, parent, *mSettings, foundUnspecified); + if (mTokenizer->isCPP() && mSettings.standards.cpp >= Standards::CPP11) { + if (mSettings.standards.cpp >= Standards::CPP17) + foundError = checkEvaluationOrderCpp17(tok, tok2, parent, mSettings, foundUnspecified); else - foundError = checkEvaluationOrderCpp11(tok, tok2, parent, *mSettings); + foundError = checkEvaluationOrderCpp11(tok, tok2, parent, mSettings); } else - foundError = checkEvaluationOrderC(tok, tok2, parent, *mSettings, bSelfAssignmentError); + foundError = checkEvaluationOrderC(tok, tok2, parent, mSettings, bSelfAssignmentError); if (foundError) { unknownEvaluationOrder(parent, foundUnspecified); @@ -3933,12 +3933,12 @@ void CheckOtherImpl::unknownEvaluationOrder(const Token* tok, bool isUnspecified void CheckOtherImpl::checkAccessOfMovedVariable() { - if (!mTokenizer->isCPP() || mSettings->standards.cpp < Standards::CPP11) + if (!mTokenizer->isCPP() || mSettings.standards.cpp < Standards::CPP11) return; - if (!mSettings->isPremiumEnabled("accessMoved") && !mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.isPremiumEnabled("accessMoved") && !mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckOther::checkAccessOfMovedVariable"); // c++11,warning - const bool reportInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive); + const bool reportInconclusive = mSettings.certainty.isEnabled(Certainty::inconclusive); const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { const Token * scopeStart = scope->bodyStart; @@ -3964,11 +3964,11 @@ void CheckOtherImpl::checkAccessOfMovedVariable() else inconclusive = true; } else { - const ExprUsage usage = getExprUsage(tok, 0, *mSettings); + const ExprUsage usage = getExprUsage(tok, 0, mSettings); if (usage == ExprUsage::Used) accessOfMoved = true; if (usage == ExprUsage::PassedByReference) - accessOfMoved = !isVariableChangedByFunctionCall(tok, 0, *mSettings, &inconclusive); + accessOfMoved = !isVariableChangedByFunctionCall(tok, 0, mSettings, &inconclusive); else if (usage == ExprUsage::Inconclusive) inconclusive = true; } @@ -4009,11 +4009,11 @@ void CheckOtherImpl::accessMovedError(const Token *tok, const std::string &varna void CheckOtherImpl::checkFuncArgNamesDifferent() { - const bool style = mSettings->severity.isEnabled(Severity::style); - const bool inconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive); - const bool warning = mSettings->severity.isEnabled(Severity::warning); + const bool style = mSettings.severity.isEnabled(Severity::style); + const bool inconclusive = mSettings.certainty.isEnabled(Certainty::inconclusive); + const bool warning = mSettings.severity.isEnabled(Severity::warning); - if (!(warning || (style && inconclusive)) && !mSettings->isPremiumEnabled("funcArgNamesDifferent")) + if (!(warning || (style && inconclusive)) && !mSettings.isPremiumEnabled("funcArgNamesDifferent")) return; logChecker("CheckOther::checkFuncArgNamesDifferent"); // style,warning,inconclusive @@ -4155,7 +4155,7 @@ static const Token *findShadowed(const Scope *scope, const Variable& var, int li void CheckOtherImpl::checkShadowVariables() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("shadowVariable")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("shadowVariable")) return; logChecker("CheckOther::checkShadowVariables"); // style const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); @@ -4256,7 +4256,7 @@ static bool isVariableExprHidden(const Token* tok) void CheckOtherImpl::checkKnownArgument() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("knownArgument")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("knownArgument")) return; logChecker("CheckOther::checkKnownArgument"); // style const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); @@ -4291,7 +4291,7 @@ void CheckOtherImpl::checkKnownArgument() continue; if (tok->isComparisonOp() && isSameExpression( - true, tok->astOperand1(), tok->astOperand2(), *mSettings, true, true)) + true, tok->astOperand1(), tok->astOperand2(), mSettings, true, true)) continue; // ensure that there is a integer variable in expression with unknown value const Token* vartok = nullptr; @@ -4357,7 +4357,7 @@ void CheckOtherImpl::knownArgumentError(const Token *tok, const Token *ftok, con void CheckOtherImpl::checkKnownPointerToBool() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("knownPointerToBool")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("knownPointerToBool")) return; logChecker("CheckOther::checkKnownPointerToBool"); // style const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase(); @@ -4377,7 +4377,7 @@ void CheckOtherImpl::checkKnownPointerToBool() return parent->isExpandedMacro(); })) continue; - if (!isUsedAsBool(tok, *mSettings)) + if (!isUsedAsBool(tok, mSettings)) continue; const ValueFlow::Value& value = tok->values().front(); knownPointerToBoolError(tok, &value); @@ -4428,10 +4428,10 @@ void CheckOtherImpl::checkComparePointers() continue; if (var1->isRValueReference() || var2->isRValueReference()) continue; - if (const Token* parent2 = getParentLifetime(v2.tokvalue, mSettings->library)) + if (const Token* parent2 = getParentLifetime(v2.tokvalue, mSettings.library)) if (var1 == parent2->variable()) continue; - if (const Token* parent1 = getParentLifetime(v1.tokvalue, mSettings->library)) + if (const Token* parent1 = getParentLifetime(v1.tokvalue, mSettings.library)) if (var2 == parent1->variable()) continue; comparePointersError(tok, &v1, &v2); @@ -4461,7 +4461,7 @@ void CheckOtherImpl::comparePointersError(const Token *tok, const ValueFlow::Val void CheckOtherImpl::checkModuloOfOne() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("moduloofone")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("moduloofone")) return; logChecker("CheckOther::checkModuloOfOne"); // style @@ -4571,7 +4571,7 @@ static bool isZeroInitializer(const Token *tok) void CheckOtherImpl::checkUnionZeroInit() { - if (!mSettings->severity.isEnabled(Severity::portability)) + if (!mSettings.severity.isEnabled(Severity::portability)) return; logChecker("CheckOther::checkUnionZeroInit"); // portability @@ -4579,7 +4579,7 @@ void CheckOtherImpl::checkUnionZeroInit() const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); std::unordered_map unionsByScopeId; - const std::vector unions = parseUnions(*symbolDatabase, *mSettings); + const std::vector unions = parseUnions(*symbolDatabase, mSettings); for (const Union &u : unions) { unionsByScopeId.emplace(u.scope, u); } @@ -4718,7 +4718,7 @@ void CheckOtherImpl::checkOverlappingWrite() if (errorToken) overlappingWriteUnion(tok); } else if (Token::Match(tok, "%name% (")) { - const Library::NonOverlappingData *nonOverlappingData = mSettings->library.getNonOverlappingData(tok); + const Library::NonOverlappingData *nonOverlappingData = mSettings.library.getNonOverlappingData(tok); if (!nonOverlappingData) continue; const std::vector args = getArguments(tok); @@ -4743,7 +4743,7 @@ void CheckOtherImpl::checkOverlappingWrite() constexpr bool macro = true; constexpr bool pure = true; constexpr bool follow = true; - if (!isSameExpression(macro, ptr1, ptr2, *mSettings, pure, follow, &errorPath)) + if (!isSameExpression(macro, ptr1, ptr2, mSettings, pure, follow, &errorPath)) continue; overlappingWriteFunction(tok, tok->str()); } @@ -4755,9 +4755,9 @@ void CheckOtherImpl::checkOverlappingWrite() MathLib::bigint sizeValue = args[sizeArg-1]->getKnownIntValue(); const Token *buf1, *buf2; MathLib::bigint offset1, offset2; - if (!getBufAndOffset(ptr1, buf1, &offset1, *mSettings, isCountArg ? &sizeValue : nullptr)) + if (!getBufAndOffset(ptr1, buf1, &offset1, mSettings, isCountArg ? &sizeValue : nullptr)) continue; - if (!getBufAndOffset(ptr2, buf2, &offset2, *mSettings)) + if (!getBufAndOffset(ptr2, buf2, &offset2, mSettings)) continue; if (offset1 < offset2 && offset1 + sizeValue <= offset2) @@ -4769,7 +4769,7 @@ void CheckOtherImpl::checkOverlappingWrite() constexpr bool macro = true; constexpr bool pure = true; constexpr bool follow = true; - if (!isSameExpression(macro, buf1, buf2, *mSettings, pure, follow, &errorPath)) + if (!isSameExpression(macro, buf1, buf2, mSettings, pure, follow, &errorPath)) continue; overlappingWriteFunction(tok, tok->str()); } @@ -4789,7 +4789,7 @@ void CheckOtherImpl::overlappingWriteFunction(const Token *tok, const std::strin void CheckOther::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckOtherImpl checkOther(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckOtherImpl checkOther(&tokenizer, tokenizer.getSettings(), errorLogger); // Checks checkOther.warningOldStylePointerCast(); @@ -4839,7 +4839,7 @@ void CheckOther::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) checkOther.checkUnionZeroInit(); } -void CheckOther::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckOther::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckOtherImpl c(nullptr, settings, errorLogger); diff --git a/lib/checkother.h b/lib/checkother.h index 6f6460bdfde..c3c045653c8 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -62,7 +62,7 @@ class CPPCHECKLIB CheckOther : public Check { /** @brief Run checks against the normal token list */ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { return "Other checks\n" @@ -127,7 +127,7 @@ class CPPCHECKLIB CheckOther : public Check { class CPPCHECKLIB CheckOtherImpl : public CheckImpl { public: /** @brief This constructor is used when running checks. */ - CheckOtherImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckOtherImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** Is expression a comparison that checks if a nonzero (unsigned/pointer) expression is less than zero? */ diff --git a/lib/checkpostfixoperator.cpp b/lib/checkpostfixoperator.cpp index 0b02313b672..e0026e1d70c 100644 --- a/lib/checkpostfixoperator.cpp +++ b/lib/checkpostfixoperator.cpp @@ -39,7 +39,7 @@ static const CWE CWE398(398U); // Indicator of Poor Code Quality void CheckPostfixOperatorImpl::postfixOperator() { - if (!mSettings->severity.isEnabled(Severity::performance)) + if (!mSettings.severity.isEnabled(Severity::performance)) return; logChecker("CheckPostfixOperator::postfixOperator"); // performance @@ -99,11 +99,11 @@ void CheckPostfixOperator::runChecks(const Tokenizer &tokenizer, ErrorLogger *er if (tokenizer.isC()) return; - CheckPostfixOperatorImpl checkPostfixOperator(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckPostfixOperatorImpl checkPostfixOperator(&tokenizer, tokenizer.getSettings(), errorLogger); checkPostfixOperator.postfixOperator(); } -void CheckPostfixOperator::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckPostfixOperator::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckPostfixOperatorImpl c(nullptr, settings, errorLogger); c.postfixOperatorError(nullptr); diff --git a/lib/checkpostfixoperator.h b/lib/checkpostfixoperator.h index 03ab54eed11..27d833a992e 100644 --- a/lib/checkpostfixoperator.h +++ b/lib/checkpostfixoperator.h @@ -50,7 +50,7 @@ class CPPCHECKLIB CheckPostfixOperator : public Check { private: void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { return "Warn if using postfix operators ++ or -- rather than prefix operator\n"; } @@ -59,7 +59,7 @@ class CPPCHECKLIB CheckPostfixOperator : public Check { class CPPCHECKLIB CheckPostfixOperatorImpl : public CheckImpl { public: /** This constructor is used when running checks. */ - CheckPostfixOperatorImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckPostfixOperatorImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** Check postfix operators */ diff --git a/lib/checksizeof.cpp b/lib/checksizeof.cpp index ab398dda570..694f73eeff6 100644 --- a/lib/checksizeof.cpp +++ b/lib/checksizeof.cpp @@ -41,7 +41,7 @@ static const CWE CWE682(682U); // Incorrect Calculation //--------------------------------------------------------------------------- void CheckSizeofImpl::checkSizeofForNumericParameter() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckSizeof::checkSizeofForNumericParameter"); // warning @@ -71,7 +71,7 @@ void CheckSizeofImpl::sizeofForNumericParameterError(const Token *tok) //--------------------------------------------------------------------------- void CheckSizeofImpl::checkSizeofForArrayParameter() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckSizeof::checkSizeofForArrayParameter"); // warning @@ -112,7 +112,7 @@ void CheckSizeofImpl::sizeofForArrayParameterError(const Token *tok) void CheckSizeofImpl::checkSizeofForPointerSize() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckSizeof::checkSizeofForPointerSize"); // warning @@ -129,7 +129,7 @@ void CheckSizeofImpl::checkSizeofForPointerSize() // Once leaving those tests, it is mandatory to have: // - variable matching the used pointer // - tokVar pointing on the argument where sizeof may be used - if (Token::Match(tok->tokAt(2), "%name% (") && mSettings->library.getAllocFuncInfo(tok->tokAt(2))) { + if (Token::Match(tok->tokAt(2), "%name% (") && mSettings.library.getAllocFuncInfo(tok->tokAt(2))) { if (Token::Match(tok, "%var% =")) variable = tok; else if (tok->strAt(1) == ")" && Token::Match(tok->linkAt(1)->tokAt(-2), "%var% =")) @@ -282,7 +282,7 @@ void CheckSizeofImpl::divideBySizeofError(const Token *tok, const std::string &m //----------------------------------------------------------------------------- void CheckSizeofImpl::sizeofsizeof() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckSizeof::sizeofsizeof"); // warning @@ -308,12 +308,12 @@ void CheckSizeofImpl::sizeofsizeofError(const Token *tok) void CheckSizeofImpl::sizeofCalculation() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckSizeof::sizeofCalculation"); // warning - const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive); + const bool printInconclusive = mSettings.certainty.isEnabled(Certainty::inconclusive); for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) { if (!Token::simpleMatch(tok, "sizeof (")) @@ -354,7 +354,7 @@ void CheckSizeofImpl::sizeofCalculationError(const Token *tok, bool inconclusive void CheckSizeofImpl::sizeofFunction() { - if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("sizeofFunctionCall")) + if (!mSettings.severity.isEnabled(Severity::warning) && !mSettings.isPremiumEnabled("sizeofFunctionCall")) return; logChecker("CheckSizeof::sizeofFunction"); // warning @@ -397,7 +397,7 @@ void CheckSizeofImpl::sizeofFunctionError(const Token *tok) //----------------------------------------------------------------------------- void CheckSizeofImpl::suspiciousSizeofCalculation() { - if (!mSettings->severity.isEnabled(Severity::warning) || !mSettings->certainty.isEnabled(Certainty::inconclusive)) + if (!mSettings.severity.isEnabled(Severity::warning) || !mSettings.certainty.isEnabled(Certainty::inconclusive)) return; logChecker("CheckSizeof::suspiciousSizeofCalculation"); // warning,inconclusive @@ -441,7 +441,7 @@ void CheckSizeofImpl::divideSizeofError(const Token *tok) void CheckSizeofImpl::sizeofVoid() { - if (!mSettings->severity.isEnabled(Severity::portability)) + if (!mSettings.severity.isEnabled(Severity::portability)) return; logChecker("CheckSizeof::sizeofVoid"); // portability @@ -500,7 +500,7 @@ void CheckSizeofImpl::arithOperationsOnVoidPointerError(const Token* tok, const void CheckSizeof::runChecks(const Tokenizer& tokenizer, ErrorLogger* errorLogger) { - CheckSizeofImpl checkSizeof(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckSizeofImpl checkSizeof(&tokenizer, tokenizer.getSettings(), errorLogger); // Checks checkSizeof.sizeofsizeof(); @@ -513,7 +513,7 @@ void CheckSizeof::runChecks(const Tokenizer& tokenizer, ErrorLogger* errorLogger checkSizeof.sizeofVoid(); } -void CheckSizeof::getErrorMessages(ErrorLogger* errorLogger, const Settings* settings) const +void CheckSizeof::getErrorMessages(ErrorLogger* errorLogger, const Settings& settings) const { CheckSizeofImpl c(nullptr, settings, errorLogger); c.sizeofForArrayParameterError(nullptr); diff --git a/lib/checksizeof.h b/lib/checksizeof.h index 0ec4b298de5..90d55e69506 100644 --- a/lib/checksizeof.h +++ b/lib/checksizeof.h @@ -48,7 +48,7 @@ class CPPCHECKLIB CheckSizeof : public Check { /** @brief Run checks against the normal token list */ void runChecks(const Tokenizer& tokenizer, ErrorLogger* errorLogger) override; - void getErrorMessages(ErrorLogger* errorLogger, const Settings* settings) const override; + void getErrorMessages(ErrorLogger* errorLogger, const Settings& settings) const override; std::string classInfo() const override { return "sizeof() usage checks\n" @@ -66,7 +66,7 @@ class CPPCHECKLIB CheckSizeof : public Check { class CPPCHECKLIB CheckSizeofImpl : public CheckImpl { public: /** @brief This constructor is used when running checks. */ - CheckSizeofImpl(const Tokenizer* tokenizer, const Settings* settings, ErrorLogger* errorLogger) + CheckSizeofImpl(const Tokenizer* tokenizer, const Settings& settings, ErrorLogger* errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** @brief %Check for 'sizeof sizeof ..' */ diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 2980fe2d86e..887f7001ef2 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -150,9 +150,9 @@ void CheckStlImpl::outOfBounds() continue; if (value.isImpossible()) continue; - if (value.isInconclusive() && !mSettings->certainty.isEnabled(Certainty::inconclusive)) + if (value.isInconclusive() && !mSettings.certainty.isEnabled(Certainty::inconclusive)) continue; - if (!value.errorSeverity() && !mSettings->severity.isEnabled(Severity::warning)) + if (!value.errorSeverity() && !mSettings.severity.isEnabled(Severity::warning)) continue; if (value.intvalue == 0 && (indexTok || (containerYieldsElement(container, parent) && !containerAppendsElement(container, parent)) || @@ -165,7 +165,7 @@ void CheckStlImpl::outOfBounds() } if (indexTok) { std::vector indexValues = - ValueFlow::isOutOfBounds(value, indexTok, mSettings->severity.isEnabled(Severity::warning)); + ValueFlow::isOutOfBounds(value, indexTok, mSettings.severity.isEnabled(Severity::warning)); if (!indexValues.empty()) { outOfBoundsError( accessTok, tok->expressionString(), &value, indexTok->expressionString(), &indexValues.front()); @@ -175,7 +175,7 @@ void CheckStlImpl::outOfBounds() } if (indexTok && !indexTok->hasKnownIntValue()) { const ValueFlow::Value* value = - ValueFlow::findValue(indexTok->values(), *mSettings, [&](const ValueFlow::Value& v) { + ValueFlow::findValue(indexTok->values(), mSettings, [&](const ValueFlow::Value& v) { if (!v.isSymbolicValue()) return false; if (v.isImpossible()) @@ -280,7 +280,7 @@ bool CheckStlImpl::isContainerSize(const Token *containerToken, const Token *exp return false; if (!Token::Match(expr->astOperand1(), ". %name% (")) return false; - if (!isSameExpression(false, containerToken, expr->astOperand1()->astOperand1(), *mSettings, false, false)) + if (!isSameExpression(false, containerToken, expr->astOperand1()->astOperand1(), mSettings, false, false)) return false; return containerToken->valueType()->container->getYield(expr->strAt(-1)) == Library::Container::Yield::SIZE; } @@ -309,7 +309,7 @@ bool CheckStlImpl::isContainerSizeGE(const Token * containerToken, const Token * op = expr->astOperand1(); else return false; - return op && op->getValueGE(0, *mSettings); + return op && op->getValueGE(0, mSettings); } return false; } @@ -470,7 +470,7 @@ void CheckStlImpl::iterators() bool inconclusiveType=false; if (!isIterator(var, inconclusiveType)) continue; - if (inconclusiveType && !mSettings->certainty.isEnabled(Certainty::inconclusive)) + if (inconclusiveType && !mSettings.certainty.isEnabled(Certainty::inconclusive)) continue; const int iteratorId = var->declarationId(); @@ -772,7 +772,7 @@ bool CheckStlImpl::checkIteratorPair(const Token* tok1, const Token* tok2) (!astIsContainer(val1.tokvalue) || !astIsContainer(val2.tokvalue))) return false; } - if (isSameIteratorContainerExpression(val1.tokvalue, val2.tokvalue, *mSettings, val1.lifetimeKind)) + if (isSameIteratorContainerExpression(val1.tokvalue, val2.tokvalue, mSettings, val1.lifetimeKind)) return false; if (val1.tokvalue->expressionString() == val2.tokvalue->expressionString()) iteratorsError(tok1, val1.tokvalue, val1.tokvalue->expressionString()); @@ -792,7 +792,7 @@ bool CheckStlImpl::checkIteratorPair(const Token* tok1, const Token* tok2) const Token* iter2 = getIteratorExpression(tok2); if (!iter2) return false; - if (!isSameIteratorContainerExpression(iter1, iter2, *mSettings)) { + if (!isSameIteratorContainerExpression(iter1, iter2, mSettings)) { mismatchingContainerExpressionError(iter1, iter2); return true; } @@ -829,7 +829,7 @@ void CheckStlImpl::mismatchingContainers() // Group args together by container std::map> containers; for (int argnr = 1; argnr <= args.size(); ++argnr) { - const Library::ArgumentChecks::IteratorInfo *i = mSettings->library.getArgIteratorInfo(ftok, argnr); + const Library::ArgumentChecks::IteratorInfo *i = mSettings.library.getArgIteratorInfo(ftok, argnr); if (!i) continue; const Token * const argTok = args[argnr - 1]; @@ -846,7 +846,7 @@ void CheckStlImpl::mismatchingContainers() if (iter1.tok == iter2.tok) continue; if (iter1.info->first && iter2.info->last && - isSameExpression(false, iter1.tok, iter2.tok, *mSettings, false, false)) + isSameExpression(false, iter1.tok, iter2.tok, mSettings, false, false)) sameIteratorExpressionError(iter1.tok); if (checkIteratorPair(iter1.tok, iter2.tok)) return; @@ -910,7 +910,7 @@ void CheckStlImpl::mismatchingContainerIterator() continue; if (iterTok->str() == "*" && iterTok->astOperand1()->valueType() && iterTok->astOperand1()->valueType()->type == ValueType::ITERATOR) continue; - if (isSameIteratorContainerExpression(tok, val.tokvalue, *mSettings)) + if (isSameIteratorContainerExpression(tok, val.tokvalue, mSettings)) continue; mismatchingContainerIteratorError(tok, iterTok, val.tokvalue); } @@ -1143,7 +1143,7 @@ void CheckStlImpl::invalidContainer() const Scope* s = tok2->scope(); if (!s) continue; - if (isReturnScope(s->bodyEnd, mSettings->library)) + if (isReturnScope(s->bodyEnd, mSettings.library)) continue; invalidContainerLoopError(r.ftok, tok, r.errorPath); bail = true; @@ -1194,7 +1194,7 @@ void CheckStlImpl::invalidContainer() ErrorPath ep; bool addressOf = false; - const Variable* var = ValueFlow::getLifetimeVariable(info.tok, ep, *mSettings, &addressOf); + const Variable* var = ValueFlow::getLifetimeVariable(info.tok, ep, mSettings, &addressOf); // Check the reference is created before the change if (var && var->declarationId() == r.tok->varId() && !addressOf) { // An argument always reaches @@ -1371,10 +1371,10 @@ void CheckStlImpl::negativeIndex() const Variable * const var = tok->variable(); if (!var || tok == var->nameToken()) continue; - const Library::Container * const container = mSettings->library.detectContainer(var->typeStartToken()); + const Library::Container * const container = mSettings.library.detectContainer(var->typeStartToken()); if (!container || !container->arrayLike_indexOp) continue; - const ValueFlow::Value *index = tok->next()->astOperand2()->getValueLE(-1, *mSettings); + const ValueFlow::Value *index = tok->next()->astOperand2()->getValueLE(-1, mSettings); if (!index) continue; negativeIndexError(tok, *index); @@ -1470,7 +1470,7 @@ void CheckStlImpl::stlBoundaries() if (!var || !var->scope() || !var->scope()->isExecutable()) continue; - const Library::Container* container = mSettings->library.detectIterator(var->typeStartToken()); + const Library::Container* container = mSettings.library.detectIterator(var->typeStartToken()); if (!container || container->opLessAllowed) continue; @@ -1517,8 +1517,8 @@ static bool if_findCompare(const Token * const tokBack, bool stdStringLike) void CheckStlImpl::if_find() { - const bool printWarning = mSettings->severity.isEnabled(Severity::warning); - const bool printPerformance = mSettings->severity.isEnabled(Severity::performance); + const bool printWarning = mSettings.severity.isEnabled(Severity::warning); + const bool printPerformance = mSettings.severity.isEnabled(Severity::performance); if (!printWarning && !printPerformance) return; @@ -1542,7 +1542,7 @@ void CheckStlImpl::if_find() tok = tok->linkAt(1); else if (tok->variable() && Token::Match(tok, "%var% . %name% (")) { - container = mSettings->library.detectContainer(tok->variable()->typeStartToken()); + container = mSettings.library.detectContainer(tok->variable()->typeStartToken()); funcTok = tok->tokAt(2); } @@ -1556,16 +1556,16 @@ void CheckStlImpl::if_find() funcTok = tok2->astParent()->next(); if (tok->variable()->isArrayOrPointer()) - container = mSettings->library.detectContainer(tok->variable()->typeStartToken()); + container = mSettings.library.detectContainer(tok->variable()->typeStartToken()); else { // Container of container - find the inner container - container = mSettings->library.detectContainer(tok->variable()->typeStartToken()); // outer container + container = mSettings.library.detectContainer(tok->variable()->typeStartToken()); // outer container tok2 = Token::findsimplematch(tok->variable()->typeStartToken(), "<", tok->variable()->typeEndToken()); if (container && container->type_templateArgNo >= 0 && tok2) { tok2 = tok2->next(); for (int j = 0; j < container->type_templateArgNo; j++) tok2 = tok2->nextTemplateArgument(); - container = mSettings->library.detectContainer(tok2); // inner container + container = mSettings.library.detectContainer(tok2); // inner container } else container = nullptr; } @@ -1594,7 +1594,7 @@ void CheckStlImpl::if_find() void CheckStlImpl::if_findError(const Token *tok, bool str) { - if (str && mSettings->standards.cpp >= Standards::CPP20) + if (str && mSettings.standards.cpp >= Standards::CPP20) reportError(tok, Severity::performance, "stlIfStrFind", "Inefficient usage of string::find() in condition; string::starts_with() could be faster.\n" "Either inefficient or wrong usage of string::find(). string::starts_with() will be faster if " @@ -1685,7 +1685,7 @@ static const Token *findInsertValue(const Token *tok, const Token *containerTok, void CheckStlImpl::checkFindInsert() { - if (!mSettings->severity.isEnabled(Severity::performance)) + if (!mSettings.severity.isEnabled(Severity::performance)) return; logChecker("CheckStl::checkFindInsert"); // performance @@ -1706,20 +1706,20 @@ void CheckStlImpl::checkFindInsert() if (!containerTok) continue; // In < C++17 we only warn for small simple types - if (mSettings->standards.cpp < Standards::CPP17 && !(keyTok && keyTok->valueType() && (keyTok->valueType()->isIntegral() || keyTok->valueType()->pointer > 0))) + if (mSettings.standards.cpp < Standards::CPP17 && !(keyTok && keyTok->valueType() && (keyTok->valueType()->isIntegral() || keyTok->valueType()->pointer > 0))) continue; const Token *thenTok = tok->linkAt(1)->next(); - const Token *valueTok = findInsertValue(thenTok, containerTok, keyTok, *mSettings); + const Token *valueTok = findInsertValue(thenTok, containerTok, keyTok, mSettings); if (!valueTok) continue; if (Token::simpleMatch(thenTok->link(), "} else {")) { const Token *valueTok2 = - findInsertValue(thenTok->link()->tokAt(2), containerTok, keyTok, *mSettings); + findInsertValue(thenTok->link()->tokAt(2), containerTok, keyTok, mSettings); if (!valueTok2) continue; - if (isSameExpression(true, valueTok, valueTok2, *mSettings, true, true)) { + if (isSameExpression(true, valueTok, valueTok2, mSettings, true, true)) { checkFindInsertError(valueTok); } } else { @@ -1733,10 +1733,10 @@ void CheckStlImpl::checkFindInsertError(const Token *tok) { std::string replaceExpr; if (tok && Token::simpleMatch(tok->astParent(), "=") && tok == tok->astParent()->astOperand2() && Token::simpleMatch(tok->astParent()->astOperand1(), "[")) { - if (mSettings->standards.cpp < Standards::CPP11) + if (mSettings.standards.cpp < Standards::CPP11) // We will recommend using emplace/try_emplace instead return; - const std::string f = (mSettings->standards.cpp < Standards::CPP17) ? "emplace" : "try_emplace"; + const std::string f = (mSettings.standards.cpp < Standards::CPP17) ? "emplace" : "try_emplace"; replaceExpr = " Instead of '" + tok->astParent()->expressionString() + "' consider using '" + tok->astParent()->astOperand1()->astOperand1()->expressionString() + "." + f + "(" + @@ -1763,10 +1763,10 @@ static bool isCpp03ContainerSizeSlow(const Token *tok) void CheckStlImpl::size() { - if (!mSettings->severity.isEnabled(Severity::performance)) + if (!mSettings.severity.isEnabled(Severity::performance)) return; - if (mSettings->standards.cpp >= Standards::CPP11) + if (mSettings.standards.cpp >= Standards::CPP11) return; logChecker("CheckStl::size"); // performance,c++03 @@ -1824,7 +1824,7 @@ void CheckStlImpl::sizeError(const Token *tok) void CheckStlImpl::redundantCondition() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("redundantIfRemove")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("redundantIfRemove")) return; logChecker("CheckStl::redundantCondition"); // style @@ -1865,7 +1865,7 @@ void CheckStlImpl::redundantIfRemoveError(const Token *tok) void CheckStlImpl::missingComparison() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckStl::missingComparison"); // warning @@ -2025,8 +2025,8 @@ namespace { void CheckStlImpl::string_c_str() { - const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive); - const bool printPerformance = mSettings->severity.isEnabled(Severity::performance); + const bool printInconclusive = mSettings.certainty.isEnabled(Certainty::inconclusive); + const bool printPerformance = mSettings.severity.isEnabled(Severity::performance); const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase(); @@ -2289,8 +2289,8 @@ namespace { void CheckStlImpl::uselessCalls() { - const bool printPerformance = mSettings->severity.isEnabled(Severity::performance); - const bool printWarning = mSettings->severity.isEnabled(Severity::warning); + const bool printPerformance = mSettings.severity.isEnabled(Severity::performance); + const bool printWarning = mSettings.severity.isEnabled(Severity::warning); if (!printPerformance && !printWarning) return; @@ -2416,7 +2416,7 @@ void CheckStlImpl::uselessCallsRemoveError(const Token *tok, const std::string& // E.g. if (*i && i != str.end()) { } void CheckStlImpl::checkDereferenceInvalidIterator() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckStl::checkDereferenceInvalidIterator"); // warning @@ -2480,7 +2480,7 @@ void CheckStlImpl::checkDereferenceInvalidIterator() void CheckStlImpl::checkDereferenceInvalidIterator2() { - const bool printInconclusive = (mSettings->certainty.isEnabled(Certainty::inconclusive)); + const bool printInconclusive = (mSettings.certainty.isEnabled(Certainty::inconclusive)); logChecker("CheckStl::checkDereferenceInvalidIterator2"); @@ -2550,7 +2550,7 @@ void CheckStlImpl::checkDereferenceInvalidIterator2() emptyAdvance = tok->astParent(); } } - if (!CheckNullPointerImpl::isPointerDeRef(tok, unknown, *mSettings) && !isInvalidIterator && !emptyAdvance) { + if (!CheckNullPointerImpl::isPointerDeRef(tok, unknown, mSettings) && !isInvalidIterator && !emptyAdvance) { if (!unknown) continue; inconclusive = true; @@ -2583,7 +2583,7 @@ void CheckStlImpl::dereferenceInvalidIteratorError(const Token* tok, const Value reportError(tok, Severity::warning, "derefInvalidIteratorRedundantCheck", errmsgcond, CWE825, Certainty::normal); return; } - if (!mSettings->isEnabled(value, inconclusive)) + if (!mSettings.isEnabled(value, inconclusive)) return; ErrorPath errorPath = getErrorPath(tok, value, "Dereference of an invalid iterator"); @@ -3002,7 +3002,7 @@ namespace { void CheckStlImpl::useStlAlgorithm() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("useStlAlgorithm")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("useStlAlgorithm")) return; logChecker("CheckStl::useStlAlgorithm"); // style @@ -3018,7 +3018,7 @@ void CheckStlImpl::useStlAlgorithm() if (!Token::simpleMatch(tok, "{") || !Token::simpleMatch(tok->previous(), ")")) return false; const Token* condTok = tok->linkAt(-1)->astOperand2(); - if (isConstExpression(condTok, mSettings->library)) { + if (isConstExpression(condTok, mSettings.library)) { if (condTok->str() == "<") type = ConditionOpType::MIN; else if (condTok->str() == ">") @@ -3044,7 +3044,7 @@ void CheckStlImpl::useStlAlgorithm() continue; if (!Token::simpleMatch(tok->linkAt(1), ") {")) continue; - LoopAnalyzer a{tok, mSettings}; + LoopAnalyzer a{tok, &mSettings}; std::string algoName = a.findAlgo(); if (!algoName.empty()) { useStlAlgorithmError(tok, algoName); @@ -3082,7 +3082,7 @@ void CheckStlImpl::useStlAlgorithm() // Check for single assignment bool useLoopVarInAssign{}, hasBreak{}; - const Token *assignTok = singleAssignInScope(bodyTok, loopVar->varId(), useLoopVarInAssign, hasBreak, loopType, *mSettings); + const Token *assignTok = singleAssignInScope(bodyTok, loopVar->varId(), useLoopVarInAssign, hasBreak, loopType, mSettings); if (assignTok) { if (!checkAssignee(assignTok->astOperand1())) continue; @@ -3114,7 +3114,7 @@ void CheckStlImpl::useStlAlgorithm() } // Check for container calls bool useLoopVarInMemCall; - const Token *memberAccessTok = singleMemberCallInScope(bodyTok, loopVar->varId(), useLoopVarInMemCall, *mSettings); + const Token *memberAccessTok = singleMemberCallInScope(bodyTok, loopVar->varId(), useLoopVarInMemCall, mSettings); if (memberAccessTok && loopType == LoopType::RANGE) { const Token *memberCallTok = memberAccessTok->astOperand2(); const int contVarId = memberAccessTok->astOperand1()->varId(); @@ -3147,10 +3147,10 @@ void CheckStlImpl::useStlAlgorithm() } // Check for conditionals - const Token *condBodyTok = singleConditionalInScope(bodyTok, loopVar->varId(), loopType, *mSettings); + const Token *condBodyTok = singleConditionalInScope(bodyTok, loopVar->varId(), loopType, mSettings); if (condBodyTok) { // Check for single assign - assignTok = singleAssignInScope(condBodyTok, loopVar->varId(), useLoopVarInAssign, hasBreak, loopType, *mSettings); + assignTok = singleAssignInScope(condBodyTok, loopVar->varId(), useLoopVarInAssign, hasBreak, loopType, mSettings); if (assignTok) { if (!checkAssignee(assignTok->astOperand1())) continue; @@ -3191,7 +3191,7 @@ void CheckStlImpl::useStlAlgorithm() } // Check for container call - memberAccessTok = singleMemberCallInScope(condBodyTok, loopVar->varId(), useLoopVarInMemCall, *mSettings); + memberAccessTok = singleMemberCallInScope(condBodyTok, loopVar->varId(), useLoopVarInMemCall, mSettings); if (memberAccessTok) { const Token *memberCallTok = memberAccessTok->astOperand2(); const int contVarId = memberAccessTok->astOperand1()->varId(); @@ -3269,7 +3269,7 @@ static bool isKnownEmptyContainer(const Token* tok) void CheckStlImpl::knownEmptyContainer() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("knownEmptyContainer")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("knownEmptyContainer")) return; logChecker("CheckStl::knownEmptyContainer"); // style for (const Scope *function : mTokenizer->getSymbolDatabase()->functionScopes) { @@ -3295,7 +3295,7 @@ void CheckStlImpl::knownEmptyContainer() continue; for (int argnr = 1; argnr <= args.size(); ++argnr) { - const Library::ArgumentChecks::IteratorInfo *i = mSettings->library.getArgIteratorInfo(tok, argnr); + const Library::ArgumentChecks::IteratorInfo *i = mSettings.library.getArgIteratorInfo(tok, argnr); if (!i) continue; const Token * const argTok = args[argnr - 1]; @@ -3418,7 +3418,7 @@ void CheckStlImpl::localMutexError(const Token* tok) void CheckStlImpl::checkMutexes() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckStl::checkMutexes"); // warning for (const Scope *function : mTokenizer->getSymbolDatabase()->functionScopes) { @@ -3459,7 +3459,7 @@ void CheckStl::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) return; } - CheckStlImpl checkStl(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckStlImpl checkStl(&tokenizer, tokenizer.getSettings(), errorLogger); checkStl.erase(); checkStl.if_find(); checkStl.checkFindInsert(); @@ -3490,7 +3490,7 @@ void CheckStl::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) checkStl.size(); } -void CheckStl::getErrorMessages(ErrorLogger* errorLogger, const Settings* settings) const +void CheckStl::getErrorMessages(ErrorLogger* errorLogger, const Settings& settings) const { CheckStlImpl c(nullptr, settings, errorLogger); c.outOfBoundsError(nullptr, "container", nullptr, "x", nullptr); diff --git a/lib/checkstl.h b/lib/checkstl.h index 626e39f4276..e23d6b54fb4 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -55,7 +55,7 @@ class CPPCHECKLIB CheckStl : public Check { /** run checks, the token list is not simplified */ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger* errorLogger, const Settings* settings) const override; + void getErrorMessages(ErrorLogger* errorLogger, const Settings& settings) const override; std::string classInfo() const override { return "Check for invalid usage of STL:\n" @@ -83,7 +83,7 @@ class CPPCHECKLIB CheckStl : public Check { class CPPCHECKLIB CheckStlImpl : public CheckImpl { public: /** This constructor is used when running checks. */ - CheckStlImpl(const Tokenizer* tokenizer, const Settings* settings, ErrorLogger* errorLogger) + CheckStlImpl(const Tokenizer* tokenizer, const Settings& settings, ErrorLogger* errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** Accessing container out of bounds using ValueFlow */ diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp index 916885e094a..db4a3eca113 100644 --- a/lib/checkstring.cpp +++ b/lib/checkstring.cpp @@ -55,7 +55,7 @@ void CheckStringImpl::stringLiteralWrite() for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!tok->variable() || !tok->variable()->isPointer()) continue; - const Token *str = tok->getValueTokenMinStrSize(*mSettings); + const Token *str = tok->getValueTokenMinStrSize(mSettings); if (!str) continue; if (Token::Match(tok, "%var% [") && Token::simpleMatch(tok->linkAt(1), "] =")) @@ -91,7 +91,7 @@ void CheckStringImpl::stringLiteralWriteError(const Token *tok, const Token *str //--------------------------------------------------------------------------- void CheckStringImpl::checkAlwaysTrueOrFalseStringCompare() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckString::checkAlwaysTrueOrFalseStringCompare"); // warning @@ -160,7 +160,7 @@ void CheckStringImpl::alwaysTrueStringVariableCompareError(const Token *tok, con //----------------------------------------------------------------------------- void CheckStringImpl::checkSuspiciousStringCompare() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckString::checkSuspiciousStringCompare"); // warning @@ -274,7 +274,7 @@ static bool isMacroUsage(const Token* tok) //--------------------------------------------------------------------------- void CheckStringImpl::checkIncorrectStringCompare() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckString::checkIncorrectStringCompare"); // warning @@ -314,7 +314,7 @@ void CheckStringImpl::checkIncorrectStringCompare() } } else if (Token::Match(tok, "%str%|%char%") && !Token::Match(tok->next(), "%name%") && - isUsedAsBool(tok, *mSettings) && + isUsedAsBool(tok, mSettings) && !isMacroUsage(tok)) incorrectStringBooleanError(tok, tok->str()); } @@ -343,7 +343,7 @@ void CheckStringImpl::incorrectStringBooleanError(const Token *tok, const std::s //--------------------------------------------------------------------------- void CheckStringImpl::overlappingStrcmp() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckString::overlappingStrcmp"); // warning @@ -395,7 +395,7 @@ void CheckStringImpl::overlappingStrcmp() if (args1[1]->isLiteral() && args2[1]->isLiteral() && args1[1]->str() != args2[1]->str() && - isSameExpression(true, args1[0], args2[0], *mSettings, true, false)) + isSameExpression(true, args1[0], args2[0], mSettings, true, false)) overlappingStrcmpError(eq0, ne0); } } @@ -446,7 +446,7 @@ void CheckStringImpl::sprintfOverlappingData() const bool same = isSameExpression(false, dest, arg, - *mSettings, + mSettings, true, false); if (same) { @@ -473,7 +473,7 @@ void CheckStringImpl::sprintfOverlappingDataError(const Token *funcTok, const To void CheckString::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckStringImpl checkString(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckStringImpl checkString(&tokenizer, tokenizer.getSettings(), errorLogger); // Checks checkString.strPlusChar(); @@ -485,7 +485,7 @@ void CheckString::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger checkString.checkAlwaysTrueOrFalseStringCompare(); } -void CheckString::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckString::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckStringImpl c(nullptr, settings, errorLogger); c.stringLiteralWriteError(nullptr, nullptr); diff --git a/lib/checkstring.h b/lib/checkstring.h index 9edefc3f8b0..054c4208a18 100644 --- a/lib/checkstring.h +++ b/lib/checkstring.h @@ -48,7 +48,7 @@ class CPPCHECKLIB CheckString : public Check { /** @brief Run checks against the normal token list */ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { return "Detect misusage of C-style strings:\n" @@ -65,7 +65,7 @@ class CPPCHECKLIB CheckString : public Check { class CPPCHECKLIB CheckStringImpl : public CheckImpl { public: /** @brief This constructor is used when running checks. */ - CheckStringImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckStringImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** @brief undefined behaviour, writing string literal */ diff --git a/lib/checktype.cpp b/lib/checktype.cpp index 1679d98e80f..262cb37a612 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -59,7 +59,7 @@ static const CWE CWE190(190U); // Integer Overflow or Wraparound void CheckTypeImpl::checkTooBigBitwiseShift() { // unknown sizeof(int) => can't run this checker - if (mSettings->platform.type == Platform::Type::Unspecified) + if (mSettings.platform.type == Platform::Type::Unspecified) return; logChecker("CheckType::checkTooBigBitwiseShift"); // platform @@ -90,21 +90,21 @@ void CheckTypeImpl::checkTooBigBitwiseShift() (lhstype->type == ValueType::Type::WCHAR_T) || (lhstype->type == ValueType::Type::BOOL) || (lhstype->type == ValueType::Type::INT)) - lhsbits = mSettings->platform.int_bit; + lhsbits = mSettings.platform.int_bit; else if (lhstype->type == ValueType::Type::LONG) - lhsbits = mSettings->platform.long_bit; + lhsbits = mSettings.platform.long_bit; else if (lhstype->type == ValueType::Type::LONGLONG) - lhsbits = mSettings->platform.long_long_bit; + lhsbits = mSettings.platform.long_long_bit; else continue; // Get biggest rhs value. preferably a value which doesn't have 'condition'. - const ValueFlow::Value * value = tok->astOperand2()->getValueGE(lhsbits, *mSettings); - if (value && mSettings->isEnabled(value, false)) + const ValueFlow::Value * value = tok->astOperand2()->getValueGE(lhsbits, mSettings); + if (value && mSettings.isEnabled(value, false)) tooBigBitwiseShiftError(tok, lhsbits, *value); else if (lhstype->sign == ValueType::Sign::SIGNED) { - value = tok->astOperand2()->getValueGE(lhsbits-1, *mSettings); - if (value && mSettings->isEnabled(value, false)) + value = tok->astOperand2()->getValueGE(lhsbits-1, mSettings); + if (value && mSettings.isEnabled(value, false)) tooBigSignedBitwiseShiftError(tok, lhsbits, *value); } } @@ -133,7 +133,7 @@ void CheckTypeImpl::tooBigSignedBitwiseShiftError(const Token *tok, int lhsbits, { constexpr char id[] = "shiftTooManyBitsSigned"; - const bool cpp14 = ((tok && tok->isCpp()) || (mTokenizer && mTokenizer->isCPP())) && (mSettings->standards.cpp >= Standards::CPP14); + const bool cpp14 = ((tok && tok->isCpp()) || (mTokenizer && mTokenizer->isCPP())) && (mSettings.standards.cpp >= Standards::CPP14); std::string behaviour = "undefined"; if (cpp14) @@ -148,7 +148,7 @@ void CheckTypeImpl::tooBigSignedBitwiseShiftError(const Token *tok, int lhsbits, if (cpp14) severity = Severity::portability; - if ((severity == Severity::portability) && !mSettings->severity.isEnabled(Severity::portability)) + if ((severity == Severity::portability) && !mSettings.severity.isEnabled(Severity::portability)) return; ErrorPath errorPath = getErrorPath(tok, &rhsbits, "Shift"); @@ -167,7 +167,7 @@ void CheckTypeImpl::tooBigSignedBitwiseShiftError(const Token *tok, int lhsbits, void CheckTypeImpl::checkIntegerOverflow() { // unknown sizeof(int) => can't run this checker - if (mSettings->platform.type == Platform::Type::Unspecified || mSettings->platform.int_bit >= MathLib::bigint_bits) + if (mSettings.platform.type == Platform::Type::Unspecified || mSettings.platform.int_bit >= MathLib::bigint_bits) return; logChecker("CheckType::checkIntegerOverflow"); // platform @@ -183,11 +183,11 @@ void CheckTypeImpl::checkIntegerOverflow() unsigned int bits; if (vt->type == ValueType::Type::INT) - bits = mSettings->platform.int_bit; + bits = mSettings.platform.int_bit; else if (vt->type == ValueType::Type::LONG) - bits = mSettings->platform.long_bit; + bits = mSettings.platform.long_bit; else if (vt->type == ValueType::Type::LONGLONG) - bits = mSettings->platform.long_long_bit; + bits = mSettings.platform.long_long_bit; else continue; @@ -199,12 +199,12 @@ void CheckTypeImpl::checkIntegerOverflow() // is there a overflow result value bool isOverflow = true; - const ValueFlow::Value *value = tok->getValueGE(maxvalue + 1, *mSettings); + const ValueFlow::Value *value = tok->getValueGE(maxvalue + 1, mSettings); if (!value) { - value = tok->getValueLE(-maxvalue - 2, *mSettings); + value = tok->getValueLE(-maxvalue - 2, mSettings); isOverflow = false; } - if (!value || !mSettings->isEnabled(value,false)) + if (!value || !mSettings.isEnabled(value,false)) continue; // For left shift, it's common practice to shift into the sign bit @@ -253,7 +253,7 @@ void CheckTypeImpl::integerOverflowError(const Token *tok, const ValueFlow::Valu void CheckTypeImpl::checkSignConversion() { - if (!mSettings->severity.isEnabled(Severity::warning)) + if (!mSettings.severity.isEnabled(Severity::warning)) return; logChecker("CheckType::checkSignConversion"); // warning @@ -272,7 +272,7 @@ void CheckTypeImpl::checkSignConversion() if (!tok1) continue; const ValueFlow::Value* negativeValue = - ValueFlow::findValue(tok1->values(), *mSettings, [&](const ValueFlow::Value& v) { + ValueFlow::findValue(tok1->values(), mSettings, [&](const ValueFlow::Value& v) { return !v.isImpossible() && v.isIntValue() && (v.intvalue <= -1 || v.wideintvalue <= -1); }); if (!negativeValue) @@ -338,7 +338,7 @@ static bool checkTypeCombination(ValueType src, ValueType tgt, const Settings& s void CheckTypeImpl::checkLongCast() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("truncLongCastAssignment")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("truncLongCastAssignment")) return; logChecker("CheckType::checkLongCast"); // style @@ -349,7 +349,7 @@ void CheckTypeImpl::checkLongCast() continue; if (const ValueFlow::Value* v = tok->astOperand2()->getKnownValue(ValueFlow::Value::ValueType::INT)) { - if (mSettings->platform.isIntValue(v->intvalue)) + if (mSettings.platform.isIntValue(v->intvalue)) continue; } @@ -358,7 +358,7 @@ void CheckTypeImpl::checkLongCast() if (!lhstype || !rhstype) continue; - if (!checkTypeCombination(*rhstype, *lhstype, *mSettings)) + if (!checkTypeCombination(*rhstype, *lhstype, mSettings)) continue; // assign int result to long/longlong const nonpointer? @@ -385,12 +385,12 @@ void CheckTypeImpl::checkLongCast() if (tok->str() == "return") { if (Token::Match(tok->astOperand1(), "<<|*")) { const ValueType *type = tok->astOperand1()->valueType(); - if (type && checkTypeCombination(*type, *retVt, *mSettings) && + if (type && checkTypeCombination(*type, *retVt, mSettings) && type->pointer == 0U && type->originalTypeName.empty()) { if (!tok->astOperand1()->hasKnownIntValue()) { ret = tok; - } else if (!mSettings->platform.isIntValue(tok->astOperand1()->getKnownIntValue())) + } else if (!mSettings.platform.isIntValue(tok->astOperand1()->getKnownIntValue())) ret = tok; } } @@ -476,7 +476,7 @@ void CheckTypeImpl::checkFloatToIntegerOverflow() while (scope && scope->type != ScopeType::eLambda && scope->type != ScopeType::eFunction) scope = scope->nestedIn; if (scope && scope->type == ScopeType::eFunction && scope->function && scope->function->retDef) { - const ValueType &valueType = ValueType::parseDecl(scope->function->retDef, *mSettings); + const ValueType &valueType = ValueType::parseDecl(scope->function->retDef, mSettings); vtfloat = tok->astOperand1()->valueType(); checkFloatToIntegerOverflow(tok, &valueType, vtfloat, tok->astOperand1()->values()); } @@ -495,24 +495,24 @@ void CheckTypeImpl::checkFloatToIntegerOverflow(const Token *tok, const ValueTyp for (const ValueFlow::Value &f : floatValues) { if (f.valueType != ValueFlow::Value::ValueType::FLOAT) continue; - if (!mSettings->isEnabled(&f, false)) + if (!mSettings.isEnabled(&f, false)) continue; - if (f.floatValue >= std::exp2(mSettings->platform.long_long_bit)) + if (f.floatValue >= std::exp2(mSettings.platform.long_long_bit)) floatToIntegerOverflowError(tok, f); - else if ((-f.floatValue) > std::exp2(mSettings->platform.long_long_bit - 1)) + else if ((-f.floatValue) > std::exp2(mSettings.platform.long_long_bit - 1)) floatToIntegerOverflowError(tok, f); - else if (mSettings->platform.type != Platform::Type::Unspecified) { + else if (mSettings.platform.type != Platform::Type::Unspecified) { int bits = 0; if (vtint->type == ValueType::Type::CHAR) - bits = mSettings->platform.char_bit; + bits = mSettings.platform.char_bit; else if (vtint->type == ValueType::Type::SHORT) - bits = mSettings->platform.short_bit; + bits = mSettings.platform.short_bit; else if (vtint->type == ValueType::Type::INT) - bits = mSettings->platform.int_bit; + bits = mSettings.platform.int_bit; else if (vtint->type == ValueType::Type::LONG) - bits = mSettings->platform.long_bit; + bits = mSettings.platform.long_bit; else if (vtint->type == ValueType::Type::LONGLONG) - bits = mSettings->platform.long_long_bit; + bits = mSettings.platform.long_long_bit; else continue; if (bits < MathLib::bigint_bits && f.floatValue >= (1ULL << bits)) @@ -534,7 +534,7 @@ void CheckTypeImpl::floatToIntegerOverflowError(const Token *tok, const ValueFlo void CheckType::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { // These are not "simplified" because casts can't be ignored - CheckTypeImpl checkType(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckTypeImpl checkType(&tokenizer, tokenizer.getSettings(), errorLogger); checkType.checkTooBigBitwiseShift(); checkType.checkIntegerOverflow(); checkType.checkSignConversion(); @@ -542,7 +542,7 @@ void CheckType::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) checkType.checkFloatToIntegerOverflow(); } -void CheckType::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckType::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckTypeImpl c(nullptr, settings, errorLogger); c.tooBigBitwiseShiftError(nullptr, 32, ValueFlow::Value(64)); diff --git a/lib/checktype.h b/lib/checktype.h index a65ed7ea084..0030e3622be 100644 --- a/lib/checktype.h +++ b/lib/checktype.h @@ -54,7 +54,7 @@ class CPPCHECKLIB CheckType : public Check { /** @brief Run checks against the normal token list */ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { return "Type checks\n" @@ -70,7 +70,7 @@ class CPPCHECKLIB CheckType : public Check { class CPPCHECKLIB CheckTypeImpl : public CheckImpl { public: /** @brief This constructor is used when running checks. */ - CheckTypeImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckTypeImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** @brief %Check for bitwise shift with too big right operand */ diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 819bfa9d85a..bdfc07a8d47 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -212,10 +212,10 @@ void CheckUninitVarImpl::checkScope(const Scope* scope, const std::setbodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "[;{}] %varid% =", arg.declarationId())) continue; - const Token *allocFuncCallToken = findAllocFuncCallToken(tok->tokAt(2)->astOperand2(), mSettings->library); + const Token *allocFuncCallToken = findAllocFuncCallToken(tok->tokAt(2)->astOperand2(), mSettings.library); if (!allocFuncCallToken) continue; - const Library::AllocFunc *allocFunc = mSettings->library.getAllocFuncInfo(allocFuncCallToken); + const Library::AllocFunc *allocFunc = mSettings.library.getAllocFuncInfo(allocFuncCallToken); if (!allocFunc || allocFunc->initData) continue; @@ -396,7 +396,7 @@ static bool isVariableUsed(const Token *tok, const Variable& var) bool CheckUninitVarImpl::checkScopeForVariable(const Token *tok, const Variable& var, bool * const possibleInit, bool * const noreturn, Alloc* const alloc, const std::string &membervar, std::map& variableValue) { const bool suppressErrors(possibleInit && *possibleInit); // Assume that this is a variable declaration, rather than a fundef - const bool printDebug = mSettings->debugwarnings; + const bool printDebug = mSettings.debugwarnings; if (possibleInit) *possibleInit = false; @@ -763,7 +763,7 @@ bool CheckUninitVarImpl::checkScopeForVariable(const Token *tok, const Variable& while (rhs && rhs->isCast()) rhs = rhs->astOperand2() ? rhs->astOperand2() : rhs->astOperand1(); if (rhs && Token::Match(rhs->previous(), "%name% (")) { - const Library::AllocFunc *allocFunc = mSettings->library.getAllocFuncInfo(rhs->astOperand1()); + const Library::AllocFunc *allocFunc = mSettings.library.getAllocFuncInfo(rhs->astOperand1()); if (allocFunc && !allocFunc->initData) { *alloc = NO_CTOR_CALL; continue; @@ -1355,7 +1355,7 @@ const Token* CheckUninitVarImpl::isVariableUsage(const Token *vartok, const Libr const Token* CheckUninitVarImpl::isVariableUsage(const Token *vartok, bool pointer, Alloc alloc, int indirect) const { - return isVariableUsage(vartok, mSettings->library, pointer, alloc, indirect); + return isVariableUsage(vartok, mSettings.library, pointer, alloc, indirect); } /*** @@ -1436,7 +1436,7 @@ int CheckUninitVarImpl::isFunctionParUsage(const Token *vartok, const Library& l int CheckUninitVarImpl::isFunctionParUsage(const Token *vartok, bool pointer, Alloc alloc, int indirect) const { - return isFunctionParUsage(vartok, mSettings->library, pointer, alloc, indirect); + return isFunctionParUsage(vartok, mSettings.library, pointer, alloc, indirect); } bool CheckUninitVarImpl::isMemberVariableAssignment(const Token *tok, const std::string &membervar) const @@ -1483,9 +1483,9 @@ bool CheckUninitVarImpl::isMemberVariableAssignment(const Token *tok, const std: // check how function handle uninitialized data arguments.. const Function *function = ftok->function(); - if (!function && mSettings) { + if (!function) { // Function definition not seen, check if direction is specified in the library configuration - const Library::ArgumentChecks::Direction argDirection = mSettings->library.getArgDirection(ftok, 1 + argumentNumber); + const Library::ArgumentChecks::Direction argDirection = mSettings.library.getArgDirection(ftok, 1 + argumentNumber); if (argDirection == Library::ArgumentChecks::Direction::DIR_IN) return false; if (argDirection == Library::ArgumentChecks::Direction::DIR_OUT) @@ -1570,7 +1570,7 @@ void CheckUninitVarImpl::uninitvarError(const Token *tok, const std::string &var void CheckUninitVarImpl::uninitvarError(const Token* tok, const ValueFlow::Value& v) { - if (!mSettings->isEnabled(&v)) + if (!mSettings.isEnabled(&v)) return; if (diag(tok)) return; @@ -1660,28 +1660,28 @@ void CheckUninitVarImpl::valueFlowUninit() if (isarray && tok->variable()->isMember()) continue; // Todo: this is a bailout if (isarray && tok->variable()->isStlType() && Token::simpleMatch(tok->astParent(), ".")) { - const auto yield = astContainerYield(tok, mSettings->library); + const auto yield = astContainerYield(tok, mSettings.library); if (yield != Library::Container::Yield::AT_INDEX && yield != Library::Container::Yield::ITEM) continue; } - const bool deref = CheckNullPointerImpl::isPointerDeRef(tok, unknown, *mSettings); + const bool deref = CheckNullPointerImpl::isPointerDeRef(tok, unknown, mSettings); uninitderef = deref && v->indirect == 0; const bool isleaf = isLeafDot(tok) || uninitderef; if (!isleaf && Token::Match(tok->astParent(), ". %name%") && (tok->astParent()->next()->variable() || tok->astParent()->next()->isEnumerator())) continue; } - const ExprUsage usage = getExprUsage(tok, v->indirect, *mSettings); + const ExprUsage usage = getExprUsage(tok, v->indirect, mSettings); if (usage == ExprUsage::NotUsed || usage == ExprUsage::Inconclusive) continue; if (!v->subexpressions.empty() && usage == ExprUsage::PassedByReference) continue; if (usage != ExprUsage::Used) { if (!(Token::Match(tok->astParent(), ". %name% (|[") && uninitderef) && - isVariableChanged(tok, v->indirect, *mSettings)) + isVariableChanged(tok, v->indirect, mSettings)) continue; bool inconclusive = false; - if (isVariableChangedByFunctionCall(tok, v->indirect, *mSettings, &inconclusive) || inconclusive) + if (isVariableChangedByFunctionCall(tok, v->indirect, mSettings, &inconclusive) || inconclusive) continue; } uninitvarError(tok, *v); @@ -1753,7 +1753,7 @@ bool CheckUninitVar::analyseWholeProgram(const CTU::FileInfo &ctu, const std::li { (void)settings; - CheckUninitVarImpl dummy(nullptr, &settings, &errorLogger); + CheckUninitVarImpl dummy(nullptr, settings, &errorLogger); dummy. logChecker("CheckUninitVar::analyseWholeProgram"); @@ -1799,12 +1799,12 @@ bool CheckUninitVar::analyseWholeProgram(const CTU::FileInfo &ctu, const std::li void CheckUninitVar::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckUninitVarImpl checkUninitVar(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckUninitVarImpl checkUninitVar(&tokenizer, tokenizer.getSettings(), errorLogger); checkUninitVar.valueFlowUninit(); checkUninitVar.check(); } -void CheckUninitVar::getErrorMessages(ErrorLogger* errorLogger, const Settings* settings) const +void CheckUninitVar::getErrorMessages(ErrorLogger* errorLogger, const Settings& settings) const { CheckUninitVarImpl c(nullptr, settings, errorLogger); diff --git a/lib/checkuninitvar.h b/lib/checkuninitvar.h index f484c13e55c..e7af8f85e50 100644 --- a/lib/checkuninitvar.h +++ b/lib/checkuninitvar.h @@ -76,7 +76,7 @@ class CPPCHECKLIB CheckUninitVar : public Check { /** @brief Analyse all file infos for all TU */ bool analyseWholeProgram(const CTU::FileInfo &ctu, const std::list &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override; - void getErrorMessages(ErrorLogger* errorLogger, const Settings* settings) const override; + void getErrorMessages(ErrorLogger* errorLogger, const Settings& settings) const override; std::string classInfo() const override { return "Uninitialized variables\n" @@ -88,7 +88,7 @@ class CPPCHECKLIB CheckUninitVar : public Check { class CPPCHECKLIB CheckUninitVarImpl : public CheckImpl { public: /** @brief This constructor is used when running checks. */ - CheckUninitVarImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckUninitVarImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} enum Alloc : std::uint8_t { NO_ALLOC, NO_CTOR_CALL, CTOR_CALL, ARRAY }; diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 4c5f8175f66..b5b863badc5 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -726,8 +726,8 @@ void CheckUnusedVarImpl::checkFunctionVariableUsage_iterateScopes(const Scope* c i->typeEndToken()->isStandardType() || i->isStlType() || mTokenizer->getSymbolDatabase()->isRecordTypeWithoutSideEffects(i->type()) || - mSettings->library.detectContainer(i->typeStartToken()) || - mSettings->library.getTypeCheck("unusedvar", i->typeStartToken()->str()) == Library::TypeCheck::check) + mSettings.library.detectContainer(i->typeStartToken()) || + mSettings.library.getTypeCheck("unusedvar", i->typeStartToken()->str()) == Library::TypeCheck::check) type = Variables::standard; if (type == Variables::none || isPartOfClassStructUnion(i->typeStartToken())) @@ -852,7 +852,7 @@ void CheckUnusedVarImpl::checkFunctionVariableUsage_iterateScopes(const Scope* c } } // Freeing memory (not considered "using" the pointer if it was also allocated in this function) - if ((Token::Match(tok, "%name% ( %var% )") && mSettings->library.getDeallocFuncInfo(tok)) || + if ((Token::Match(tok, "%name% ( %var% )") && mSettings.library.getDeallocFuncInfo(tok)) || (tok->isCpp() && (Token::Match(tok, "delete %var% ;") || Token::Match(tok, "delete [ ] %var% ;")))) { nonneg int varid = 0; if (tok->str() != "delete") { @@ -958,10 +958,10 @@ void CheckUnusedVarImpl::checkFunctionVariableUsage_iterateScopes(const Scope* c // Consider allocating memory separately because allocating/freeing alone does not constitute using the variable else if (var && var->mType == Variables::pointer && Token::Match(start, "%name% =") && - findAllocFuncCallToken(start->next()->astOperand2(), mSettings->library)) { + findAllocFuncCallToken(start->next()->astOperand2(), mSettings.library)) { - const Token *allocFuncCallToken = findAllocFuncCallToken(start->next()->astOperand2(), mSettings->library); - const Library::AllocFunc *allocFunc = mSettings->library.getAllocFuncInfo(allocFuncCallToken); + const Token *allocFuncCallToken = findAllocFuncCallToken(start->next()->astOperand2(), mSettings.library); + const Library::AllocFunc *allocFunc = mSettings.library.getAllocFuncInfo(allocFuncCallToken); bool allocateMemory = !allocFunc || Library::ismemory(allocFunc->groupId); @@ -1043,7 +1043,7 @@ void CheckUnusedVarImpl::checkFunctionVariableUsage_iterateScopes(const Scope* c // Consider allocating memory separately because allocating/freeing alone does not constitute using the variable if (var->mType == Variables::pointer && ((tok->isCpp() && Token::simpleMatch(skipBrackets(tok->next()), "= new")) || - (Token::Match(skipBrackets(tok->next()), "= %name% (") && mSettings->library.getAllocFuncInfo(tok->tokAt(2))))) { + (Token::Match(skipBrackets(tok->next()), "= %name% (") && mSettings.library.getAllocFuncInfo(tok->tokAt(2))))) { variables.allocateMemory(varid, tok); } else if (var->mType == Variables::pointer || var->mType == Variables::reference) { variables.read(varid, tok); @@ -1175,7 +1175,7 @@ static bool isReturnedByRef(const Variable* var, const Function* func) void CheckUnusedVarImpl::checkFunctionVariableUsage() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->checkLibrary && !mSettings->isPremiumEnabled("unusedVariable")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.checkLibrary && !mSettings.isPremiumEnabled("unusedVariable")) return; logChecker("CheckUnusedVar::checkFunctionVariableUsage"); // style @@ -1184,7 +1184,7 @@ void CheckUnusedVarImpl::checkFunctionVariableUsage() const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); auto reportLibraryCfgError = [this](const Token* tok, const std::string& typeName) { - if (mSettings->checkLibrary) { + if (mSettings.checkLibrary) { reportError(tok, Severity::information, "checkLibraryCheckType", @@ -1331,7 +1331,7 @@ void CheckUnusedVarImpl::checkFunctionVariableUsage() std::string typeName = op1Var->getTypeName(); if (startsWith(typeName, "::")) typeName.erase(typeName.begin(), typeName.begin() + 2); - switch (mSettings->library.getTypeCheck("unusedvar", typeName)) { + switch (mSettings.library.getTypeCheck("unusedvar", typeName)) { case Library::TypeCheck::def: bailoutTypeName = std::move(typeName); break; @@ -1370,7 +1370,7 @@ void CheckUnusedVarImpl::checkFunctionVariableUsage() continue; } - FwdAnalysis fwdAnalysis(*mSettings); + FwdAnalysis fwdAnalysis(mSettings); const Token* scopeEnd = ValueFlow::getEndOfExprScope(expr, scope, /*smallest*/ false); if (fwdAnalysis.unusedValue(expr, start, scopeEnd)) { if (!bailoutTypeName.empty()) { @@ -1378,7 +1378,7 @@ void CheckUnusedVarImpl::checkFunctionVariableUsage() reportLibraryCfgError(tok, bailoutTypeName); continue; } - if (isTrivialInit && findExpressionChanged(expr, start, scopeEnd, *mSettings)) + if (isTrivialInit && findExpressionChanged(expr, start, scopeEnd, mSettings)) continue; // warn @@ -1460,7 +1460,7 @@ void CheckUnusedVarImpl::checkFunctionVariableUsage() if (mTokenizer->isCPP() && var->isClass() && (!var->valueType() || var->valueType()->type == ValueType::Type::UNKNOWN_TYPE)) { const std::string typeName = var->getTypeName(); - switch (mSettings->library.getTypeCheck("unusedvar", typeName)) { + switch (mSettings.library.getTypeCheck("unusedvar", typeName)) { case Library::TypeCheck::def: reportLibraryCfgError(vnt, typeName); break; @@ -1481,7 +1481,7 @@ void CheckUnusedVarImpl::checkFunctionVariableUsage() void CheckUnusedVarImpl::unusedVariableError(const Token *tok, const std::string &varname) { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("unusedVariable")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("unusedVariable")) return; reportError(tok, Severity::style, "unusedVariable", "$symbol:" + varname + "\nUnused variable: $symbol", CWE563, Certainty::normal); @@ -1489,7 +1489,7 @@ void CheckUnusedVarImpl::unusedVariableError(const Token *tok, const std::string void CheckUnusedVarImpl::allocatedButUnusedVariableError(const Token *tok, const std::string &varname) { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("unusedVariable")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("unusedVariable")) return; reportError(tok, Severity::style, "unusedAllocatedMemory", "$symbol:" + varname + "\nVariable '$symbol' is allocated memory that is never used.", CWE563, Certainty::normal); @@ -1497,7 +1497,7 @@ void CheckUnusedVarImpl::allocatedButUnusedVariableError(const Token *tok, const void CheckUnusedVarImpl::unreadVariableError(const Token *tok, const std::string &varname, bool modified) { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("unusedVariable")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("unusedVariable")) return; if (modified) @@ -1508,7 +1508,7 @@ void CheckUnusedVarImpl::unreadVariableError(const Token *tok, const std::string void CheckUnusedVarImpl::unassignedVariableError(const Token *tok, const std::string &varname) { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("unusedVariable")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("unusedVariable")) return; reportError(tok, Severity::style, "unassignedVariable", "$symbol:" + varname + "\nVariable '$symbol' is not assigned a value.", CWE665, Certainty::normal); @@ -1519,7 +1519,7 @@ void CheckUnusedVarImpl::unassignedVariableError(const Token *tok, const std::st //--------------------------------------------------------------------------- void CheckUnusedVarImpl::checkStructMemberUsage() { - if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("unusedStructMember") && !mSettings->isPremiumEnabled("unusedVariable")) + if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("unusedStructMember") && !mSettings.isPremiumEnabled("unusedVariable")) return; logChecker("CheckUnusedVar::checkStructMemberUsage"); // style @@ -1726,14 +1726,14 @@ bool CheckUnusedVarImpl::isEmptyType(const Type* type) void CheckUnusedVar::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckUnusedVarImpl checkUnusedVar(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckUnusedVarImpl checkUnusedVar(&tokenizer, tokenizer.getSettings(), errorLogger); // Coding style checks checkUnusedVar.checkStructMemberUsage(); checkUnusedVar.checkFunctionVariableUsage(); } -void CheckUnusedVar::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckUnusedVar::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckUnusedVarImpl c(nullptr, settings, errorLogger); c.unusedVariableError(nullptr, "varname"); diff --git a/lib/checkunusedvar.h b/lib/checkunusedvar.h index 1d2227c15bf..49ef59bee92 100644 --- a/lib/checkunusedvar.h +++ b/lib/checkunusedvar.h @@ -53,7 +53,7 @@ class CPPCHECKLIB CheckUnusedVar : public Check { /** @brief Run checks against the normal token list */ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { return "UnusedVar checks\n" @@ -70,7 +70,7 @@ class CPPCHECKLIB CheckUnusedVar : public Check { class CPPCHECKLIB CheckUnusedVarImpl : public CheckImpl { public: /** @brief This constructor is used when running checks. */ - CheckUnusedVarImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckUnusedVarImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} /** @brief %Check for unused function variables */ diff --git a/lib/checkvaarg.cpp b/lib/checkvaarg.cpp index 18eb246e0e7..42cd6852788 100644 --- a/lib/checkvaarg.cpp +++ b/lib/checkvaarg.cpp @@ -43,7 +43,7 @@ void CheckVaargImpl::va_start_argument() { const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase(); const std::size_t functions = symbolDatabase->functionScopes.size(); - const bool printWarnings = mSettings->severity.isEnabled(Severity::warning); + const bool printWarnings = mSettings.severity.isEnabled(Severity::warning); logChecker("CheckVaarg::va_start_argument"); @@ -92,7 +92,7 @@ void CheckVaargImpl::referenceAs_va_start_error(const Token *tok, const std::str void CheckVaargImpl::va_list_usage() { - if (mSettings->clang) + if (mSettings.clang) return; logChecker("CheckVaarg::va_list_usage"); // notclang @@ -175,12 +175,12 @@ void CheckVaargImpl::va_start_subsequentCallsError(const Token *tok, const std:: void CheckVaarg::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - CheckVaargImpl check(&tokenizer, &tokenizer.getSettings(), errorLogger); + CheckVaargImpl check(&tokenizer, tokenizer.getSettings(), errorLogger); check.va_start_argument(); check.va_list_usage(); } -void CheckVaarg::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void CheckVaarg::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const { CheckVaargImpl c(nullptr, settings, errorLogger); c.wrongParameterTo_va_start_error(nullptr, "arg1", "arg2"); diff --git a/lib/checkvaarg.h b/lib/checkvaarg.h index e07d653456a..4be92045427 100644 --- a/lib/checkvaarg.h +++ b/lib/checkvaarg.h @@ -47,7 +47,7 @@ class CPPCHECKLIB CheckVaarg : public Check { void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; private: - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; + void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings) const override; std::string classInfo() const override { return "Check for misusage of variable argument lists:\n" @@ -62,7 +62,7 @@ class CPPCHECKLIB CheckVaarg : public Check { class CPPCHECKLIB CheckVaargImpl : public CheckImpl { public: - CheckVaargImpl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + CheckVaargImpl(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger) : CheckImpl(tokenizer, settings, errorLogger) {} void va_start_argument(); diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index f39e64a938f..471a1a8ff1e 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1714,7 +1714,7 @@ void CppCheck::getErrorMessages(ErrorLogger &errorlogger) // call all "getErrorMessages" in all registered Check classes for (const Check * const c : CheckInstances::get()) - c->getErrorMessages(&errorlogger, &s); + c->getErrorMessages(&errorlogger, s); CheckUnusedFunctions::getErrorMessages(errorlogger); Preprocessor::getErrorMessages(errorlogger, s); diff --git a/test/test64bit.cpp b/test/test64bit.cpp index da837fd9a96..8439b5aa787 100644 --- a/test/test64bit.cpp +++ b/test/test64bit.cpp @@ -49,7 +49,7 @@ class Test64BitPortability : public TestFixture { SimpleTokenizer tokenizer(settings, *this, cpp); ASSERT_LOC(tokenizer.tokenize(code), file, line); - Check64BitPortabilityImpl check64BitPortability(&tokenizer, &settings, this); + Check64BitPortabilityImpl check64BitPortability(&tokenizer, settings, this); check64BitPortability.pointerassignment(); } diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 5d545606387..29d8fa13d17 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -5171,7 +5171,7 @@ class TestBufferOverrun : public TestFixture { // Ticket #2292: segmentation fault when using --errorlist CheckBufferOverrun check; const Check& c = getCheck(check); - c.getErrorMessages(this, nullptr); + c.getErrorMessages(this, settingsDefault); // we are not interested in the output - just consume it ignore_errout(); } diff --git a/test/testcharvar.cpp b/test/testcharvar.cpp index bb98dfad48d..ecbf6bf4dc1 100644 --- a/test/testcharvar.cpp +++ b/test/testcharvar.cpp @@ -47,7 +47,7 @@ class TestCharVar : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check char variable usage.. - CheckOtherImpl checkOther(&tokenizer, &settings, this); + CheckOtherImpl checkOther(&tokenizer, settings, this); checkOther.checkCharVariable(); } diff --git a/test/testclass.cpp b/test/testclass.cpp index 35994e98cf4..8fba8d4a340 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -270,7 +270,7 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check.. - CheckClassImpl checkClass(&tokenizer, &settings, this); + CheckClassImpl checkClass(&tokenizer, settings, this); (checkClass.checkCopyCtorAndEqOperator)(); } @@ -371,7 +371,7 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check.. - CheckClassImpl checkClass(&tokenizer, &settings0, this); + CheckClassImpl checkClass(&tokenizer, settings0, this); (checkClass.checkExplicitConstructors)(); } @@ -528,7 +528,7 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check.. - CheckClassImpl checkClass(&tokenizer, &settings1, this); + CheckClassImpl checkClass(&tokenizer, settings1, this); (checkClass.checkDuplInheritedMembers)(); } @@ -752,7 +752,7 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check.. - CheckClassImpl checkClass(&tokenizer, &settings3, this); + CheckClassImpl checkClass(&tokenizer, settings3, this); checkClass.copyconstructors(); } @@ -1223,7 +1223,7 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check.. - CheckClassImpl checkClass(&tokenizer, &settings0, this); + CheckClassImpl checkClass(&tokenizer, settings0, this); checkClass.operatorEqRetRefThis(); } @@ -1694,7 +1694,7 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check.. - CheckClassImpl checkClass(&tokenizer, &settings1, this); + CheckClassImpl checkClass(&tokenizer, settings1, this); checkClass.operatorEqToSelf(); } @@ -2657,7 +2657,7 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check.. - CheckClassImpl checkClass(&tokenizer, &s, this); + CheckClassImpl checkClass(&tokenizer, s, this); checkClass.virtualDestructor(); } @@ -2994,7 +2994,7 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check.. - CheckClassImpl checkClass(&tokenizer, &settings, this); + CheckClassImpl checkClass(&tokenizer, settings, this); checkClass.checkMemset(); } @@ -3640,7 +3640,7 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check.. - CheckClassImpl checkClass(&tokenizer, &settings1, this); + CheckClassImpl checkClass(&tokenizer, settings1, this); checkClass.thisSubtraction(); } @@ -3680,7 +3680,7 @@ class TestClass : public TestFixture { SimpleTokenizer tokenizer(settings, *this); ASSERT_LOC(tokenizer.tokenize(code), file, line); - CheckClassImpl checkClass(&tokenizer, &settings, this); + CheckClassImpl checkClass(&tokenizer, settings, this); (checkClass.checkConst)(); } @@ -7863,7 +7863,7 @@ class TestClass : public TestFixture { SimpleTokenizer tokenizer(settings2, *this); ASSERT_LOC(tokenizer.tokenize(code), file, line); - CheckClassImpl checkClass(&tokenizer, &settings2, this); + CheckClassImpl checkClass(&tokenizer, settings2, this); checkClass.initializerListOrder(); } @@ -8017,7 +8017,7 @@ class TestClass : public TestFixture { SimpleTokenizer tokenizer(settings, *this); ASSERT_LOC(tokenizer.tokenize(code), file, line); - CheckClassImpl checkClass(&tokenizer, &settings, this); + CheckClassImpl checkClass(&tokenizer, settings, this); checkClass.initializationListUsage(); } @@ -8241,7 +8241,7 @@ class TestClass : public TestFixture { SimpleTokenizer tokenizer(settings0, *this); ASSERT_LOC(tokenizer.tokenize(code), file, line); - CheckClassImpl checkClass(&tokenizer, &settings0, this); + CheckClassImpl checkClass(&tokenizer, settings0, this); (checkClass.checkSelfInitialization)(); } @@ -8351,7 +8351,7 @@ class TestClass : public TestFixture { SimpleTokenizer tokenizer(settings, *this); ASSERT_LOC(tokenizer.tokenize(code), file, line); - CheckClassImpl checkClass(&tokenizer, &settings, this); + CheckClassImpl checkClass(&tokenizer, settings, this); checkClass.checkVirtualFunctionCallInConstructor(); } @@ -8696,7 +8696,7 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check.. - CheckClassImpl checkClass(&tokenizer, &settings, this); + CheckClassImpl checkClass(&tokenizer, settings, this); (checkClass.checkOverride)(); } @@ -8908,7 +8908,7 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line); // Check.. - CheckClassImpl checkClass(&tokenizer, &settings, this); + CheckClassImpl checkClass(&tokenizer, settings, this); (checkClass.checkUselessOverride)(); } @@ -9098,7 +9098,7 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check.. - CheckClassImpl checkClass(&tokenizer, &settings, this); + CheckClassImpl checkClass(&tokenizer, settings, this); (checkClass.checkUnsafeClassRefMember)(); } @@ -9116,7 +9116,7 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check.. - CheckClassImpl checkClass(&tokenizer, &settings1, this); + CheckClassImpl checkClass(&tokenizer, settings1, this); (checkClass.checkThisUseAfterFree)(); } @@ -9353,7 +9353,7 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line); // Check.. - CheckClassImpl checkClass(&tokenizer, &settings, this); + CheckClassImpl checkClass(&tokenizer, settings, this); (checkClass.checkReturnByReference)(); } diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 8bec74529b6..155c921de80 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -52,7 +52,7 @@ class TestConstructors : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check class constructors.. - CheckClassImpl checkClass(&tokenizer, &settings1, this); + CheckClassImpl checkClass(&tokenizer, settings1, this); checkClass.constructors(); } diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index bd94b52af0e..23c6f667797 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -50,7 +50,7 @@ class TestIncompleteStatement : public TestFixture { ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line); // Check for incomplete statements.. - CheckOtherImpl checkOther(&tokenizer, &settings1, this); + CheckOtherImpl checkOther(&tokenizer, settings1, this); checkOther.checkIncompleteStatement(); } diff --git a/test/testio.cpp b/test/testio.cpp index bc6e40034f6..6d9b55ddda9 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -109,7 +109,7 @@ class TestIO : public TestFixture { // Check.. if (options.onlyFormatStr) { - CheckIOImpl checkIO(&tokenizer, &settings1, this); + CheckIOImpl checkIO(&tokenizer, settings1, this); checkIO.checkWrongPrintfScanfArguments(); return; } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 8982215d8e3..8ac0b2484ad 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -44,7 +44,7 @@ class TestMemleak : public TestFixture { SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT_LOC(tokenizer.tokenize(code), file, line); - const CheckMemoryLeakImpl c(&tokenizer, &settingsDefault, this); + const CheckMemoryLeakImpl c(&tokenizer, settingsDefault, this); return (c.functionReturnType)(&tokenizer.getSymbolDatabase()->scopeList.front().functionList.front()); } @@ -93,7 +93,7 @@ class TestMemleak : public TestFixture { // there is no allocation const Token *tok = Token::findsimplematch(tokenizer.tokens(), "ret ="); - const CheckMemoryLeakImpl check(&tokenizer, &settingsDefault, nullptr); + const CheckMemoryLeakImpl check(&tokenizer, settingsDefault, nullptr); ASSERT_EQUALS(CheckMemoryLeakImpl::No, check.getAllocationType(tok->tokAt(2), 1)); } }; @@ -119,7 +119,7 @@ class TestMemleakInFunction : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check for memory leaks.. - CheckMemoryLeakInFunctionImpl checkMemoryLeak(&tokenizer, &settings, this); + CheckMemoryLeakInFunctionImpl checkMemoryLeak(&tokenizer, settings, this); checkMemoryLeak.checkReallocUsage(); } @@ -501,7 +501,7 @@ class TestMemleakInClass : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check for memory leaks.. - CheckMemoryLeakInClassImpl checkMemoryLeak(&tokenizer, &settings, this); + CheckMemoryLeakInClassImpl checkMemoryLeak(&tokenizer, settings, this); (checkMemoryLeak.check)(); } @@ -1706,7 +1706,7 @@ class TestMemleakStructMember : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check for memory leaks.. - CheckMemoryLeakStructMemberImpl checkMemoryLeakStructMember(&tokenizer, &settings, this); + CheckMemoryLeakStructMemberImpl checkMemoryLeakStructMember(&tokenizer, settings, this); (checkMemoryLeakStructMember.check)(); } @@ -2388,7 +2388,7 @@ class TestMemleakNoVar : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check for memory leaks.. - CheckMemoryLeakNoVarImpl checkMemoryLeakNoVar(&tokenizer, &settings, this); + CheckMemoryLeakNoVarImpl checkMemoryLeakNoVar(&tokenizer, settings, this); (checkMemoryLeakNoVar.check)(); } diff --git a/test/testother.cpp b/test/testother.cpp index 321657c668f..2394cfefe7c 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2055,7 +2055,7 @@ class TestOther : public TestFixture { SimpleTokenizer tokenizerCpp(settings, *this); ASSERT_LOC(tokenizerCpp.tokenize(code), file, line); - CheckOtherImpl checkOtherCpp(&tokenizerCpp, &settings, this); + CheckOtherImpl checkOtherCpp(&tokenizerCpp, settings, this); checkOtherCpp.warningOldStylePointerCast(); checkOtherCpp.warningDangerousTypeCast(); } @@ -2341,7 +2341,7 @@ class TestOther : public TestFixture { SimpleTokenizer tokenizerCpp(settings, *this); ASSERT_LOC(tokenizerCpp.tokenize(code), file, line); - CheckOtherImpl checkOtherCpp(&tokenizerCpp, &settings, this); + CheckOtherImpl checkOtherCpp(&tokenizerCpp, settings, this); checkOtherCpp.warningIntToPointerCast(); } @@ -2380,7 +2380,7 @@ class TestOther : public TestFixture { SimpleTokenizer tokenizer(settings, *this); ASSERT_LOC(tokenizer.tokenize(code), file, line); - CheckOtherImpl checkOtherCpp(&tokenizer, &settings, this); + CheckOtherImpl checkOtherCpp(&tokenizer, settings, this); checkOtherCpp.invalidPointerCast(); } diff --git a/test/testpostfixoperator.cpp b/test/testpostfixoperator.cpp index 1d01217231a..73c864f10bc 100644 --- a/test/testpostfixoperator.cpp +++ b/test/testpostfixoperator.cpp @@ -38,7 +38,7 @@ class TestPostfixOperator : public TestFixture { SimpleTokenizer tokenizer(settings, *this); ASSERT_LOC(tokenizer.tokenize(code), file, line); - CheckPostfixOperatorImpl checkPostfixOperator(&tokenizer, &settings, this); + CheckPostfixOperatorImpl checkPostfixOperator(&tokenizer, settings, this); checkPostfixOperator.postfixOperator(); } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 6ad2047ddd7..0d71efbc897 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -127,7 +127,7 @@ class TestUninitVar : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check for redundant code.. - CheckUninitVarImpl checkuninitvar(&tokenizer, &settings1, this); + CheckUninitVarImpl checkuninitvar(&tokenizer, settings1, this); checkuninitvar.check(); } @@ -137,7 +137,7 @@ class TestUninitVar : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check for redundant code.. - CheckUninitVarImpl checkuninitvar(&tokenizer, &settings, this); + CheckUninitVarImpl checkuninitvar(&tokenizer, settings, this); checkuninitvar.check(); } @@ -3673,7 +3673,7 @@ class TestUninitVar : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check for redundant code.. - CheckUninitVarImpl checkuninitvar(&tokenizer, &settings, this); + CheckUninitVarImpl checkuninitvar(&tokenizer, settings, this); (checkuninitvar.valueFlowUninit)(); } diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index 3b419814dca..60916133f8c 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -104,7 +104,7 @@ class TestUnusedPrivateFunction : public TestFixture { ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line); // Check for unused private functions.. - CheckClassImpl checkClass(&tokenizer, &settings1, this); + CheckClassImpl checkClass(&tokenizer, settings1, this); checkClass.privateFunctions(); } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index d0ad22b004d..6419ee78c08 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -290,7 +290,7 @@ class TestUnusedVar : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check for unused variables.. - CheckUnusedVarImpl checkUnusedVar(&tokenizer, &settings, this); + CheckUnusedVarImpl checkUnusedVar(&tokenizer, settings, this); checkUnusedVar.checkFunctionVariableUsage(); } @@ -310,7 +310,7 @@ class TestUnusedVar : public TestFixture { ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check for unused variables.. - CheckUnusedVarImpl checkUnusedVar(&tokenizer, &settings, this); + CheckUnusedVarImpl checkUnusedVar(&tokenizer, settings, this); (checkUnusedVar.checkStructMemberUsage)(); } @@ -323,7 +323,7 @@ class TestUnusedVar : public TestFixture { ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line); // Check for unused variables.. - CheckUnusedVarImpl checkUnusedVar(&tokenizer, &settings, this); + CheckUnusedVarImpl checkUnusedVar(&tokenizer, settings, this); (checkUnusedVar.checkStructMemberUsage)(); } @@ -336,7 +336,7 @@ class TestUnusedVar : public TestFixture { ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line); // Check for unused variables.. - CheckUnusedVarImpl checkUnusedVar(&tokenizer, &settings, this); + CheckUnusedVarImpl checkUnusedVar(&tokenizer, settings, this); (checkUnusedVar.checkFunctionVariableUsage)(); }