Skip to content

Commit

Permalink
Fixed #12370 (Premium misra/cert/autosar: enable all corresponding ch…
Browse files Browse the repository at this point in the history
…eckers in open source cppcheck) (#5901)
  • Loading branch information
danmar authored Jan 21, 2024
1 parent 7577ad6 commit 309aa8a
Show file tree
Hide file tree
Showing 18 changed files with 302 additions and 55 deletions.
6 changes: 6 additions & 0 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,12 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
mSettings.premiumArgs += "--" + p;
if (p == "misra-c-2012" || p == "misra-c-2023")
mSettings.addons.emplace("misra");
if (startsWith(p, "autosar") || startsWith(p, "cert") || startsWith(p, "misra")) {
// All checkers related to the coding standard should be enabled. The coding standards
// do not all undefined behavior or portability issues.
mSettings.addEnabled("warning");
mSettings.addEnabled("portability");
}
}

// --project
Expand Down
4 changes: 4 additions & 0 deletions createrelease
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
# Create release candidate
# ========================
#
# check every isPremiumEnabled call:
# - every id should be in --errorlist
# - premiumaddon: check coverage.py
#
# Windows installer:
# - ensure latest build was successful
# - ensure cfg files etc are included (win_installer/cppcheck.wxs)
Expand Down
2 changes: 1 addition & 1 deletion lib/checkautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void CheckAutoVariables::assignFunctionArg()
{
const bool printStyle = mSettings->severity.isEnabled(Severity::style);
const bool printWarning = mSettings->severity.isEnabled(Severity::warning);
if (!printStyle && !printWarning)
if (!printStyle && !printWarning && !mSettings->isPremiumEnabled("uselessAssignmentPtrArg"))
return;

logChecker("CheckAutoVariables::assignFunctionArg"); // style,warning
Expand Down
2 changes: 1 addition & 1 deletion lib/checkbool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static bool isBool(const Variable* var)
//---------------------------------------------------------------------------
void CheckBool::checkIncrementBoolean()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("incrementboolean"))
return;

logChecker("CheckBool::checkIncrementBoolean"); // style
Expand Down
18 changes: 10 additions & 8 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void CheckClass::constructors()
{
const bool printStyle = mSettings->severity.isEnabled(Severity::style);
const bool printWarnings = mSettings->severity.isEnabled(Severity::warning);
if (!printStyle && !printWarnings)
if (!printStyle && !printWarnings && !mSettings->isPremiumEnabled("uninitMemberVar"))
return;

logChecker("CheckClass::checkConstructors"); // style,warning
Expand Down Expand Up @@ -336,7 +336,7 @@ void CheckClass::constructors()

void CheckClass::checkExplicitConstructors()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("noExplicitConstructor"))
return;

logChecker("CheckClass::checkExplicitConstructors"); // style
Expand Down Expand Up @@ -1275,7 +1275,7 @@ static bool checkFunctionUsage(const Function *privfunc, const Scope* scope)

void CheckClass::privateFunctions()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("unusedPrivateFunction"))
return;

logChecker("CheckClass::privateFunctions"); // style
Expand Down Expand Up @@ -1564,7 +1564,7 @@ void CheckClass::memsetErrorFloat(const Token *tok, const std::string &type)

void CheckClass::operatorEqRetRefThis()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("operatorEqRetRefThis"))
return;

logChecker("CheckClass::operatorEqRetRefThis"); // style
Expand Down Expand Up @@ -2090,7 +2090,9 @@ void CheckClass::checkConst()
if (!mSettings->certainty.isEnabled(Certainty::inconclusive))
return;

if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) &&
!mSettings->isPremiumEnabled("functionConst") &&
!mSettings->isPremiumEnabled("functionStatic"))
return;

logChecker("CheckClass::checkConst"); // style,inconclusive
Expand Down Expand Up @@ -2639,7 +2641,7 @@ namespace { // avoid one-definition-rule violation

void CheckClass::initializerListOrder()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("initializerList"))
return;

// This check is not inconclusive. However it only determines if the initialization
Expand Down Expand Up @@ -3137,7 +3139,7 @@ void CheckClass::copyCtorAndEqOperatorError(const Token *tok, const std::string

void CheckClass::checkOverride()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("missingOverride"))
return;
if (mSettings->standards.cpp < Standards::CPP11)
return;
Expand Down Expand Up @@ -3237,7 +3239,7 @@ static bool compareTokenRanges(const Token* start1, const Token* end1, const Tok

void CheckClass::checkUselessOverride()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("uselessOverride"))
return;

logChecker("CheckClass::checkUselessOverride"); // style
Expand Down
24 changes: 13 additions & 11 deletions lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bool CheckCondition::isAliased(const std::set<int> &vars) const

void CheckCondition::assignIf()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("assignIf"))
return;

logChecker("CheckCondition::assignIf"); // style
Expand Down Expand Up @@ -306,7 +306,7 @@ static bool isOperandExpanded(const Token *tok)

void CheckCondition::checkBadBitmaskCheck()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("badBitmaskCheck"))
return;

logChecker("CheckCondition::checkBadBitmaskCheck"); // style
Expand Down Expand Up @@ -354,7 +354,7 @@ void CheckCondition::badBitmaskCheckError(const Token *tok, bool isNoOp)

void CheckCondition::comparison()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("comparisonError"))
return;

logChecker("CheckCondition::comparison"); // style
Expand Down Expand Up @@ -472,7 +472,7 @@ bool CheckCondition::isOverlappingCond(const Token * const cond1, const Token *

void CheckCondition::duplicateCondition()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("duplicateCondition"))
return;

logChecker("CheckCondition::duplicateCondition"); // style
Expand Down Expand Up @@ -523,7 +523,7 @@ void CheckCondition::duplicateConditionError(const Token *tok1, const Token *tok

void CheckCondition::multiCondition()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("multiCondition"))
return;

logChecker("CheckCondition::multiCondition"); // style
Expand Down Expand Up @@ -1123,7 +1123,7 @@ void CheckCondition::checkIncorrectLogicOperator()
{
const bool printStyle = mSettings->severity.isEnabled(Severity::style);
const bool printWarning = mSettings->severity.isEnabled(Severity::warning);
if (!printWarning && !printStyle)
if (!printWarning && !printStyle && !mSettings->isPremiumEnabled("incorrectLogicOperator"))
return;
const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive);

Expand Down Expand Up @@ -1415,7 +1415,7 @@ static int countPar(const Token *tok1, const Token *tok2)
//---------------------------------------------------------------------------
void CheckCondition::clarifyCondition()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("clarifyCondition"))
return;

const bool isC = mTokenizer->isC();
Expand Down Expand Up @@ -1481,7 +1481,9 @@ void CheckCondition::clarifyConditionError(const Token *tok, bool assign, bool b

void CheckCondition::alwaysTrueFalse()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) &&
!mSettings->isPremiumEnabled("alwaysTrue") &&
!mSettings->isPremiumEnabled("alwaysFalse"))
return;

logChecker("CheckCondition::alwaysTrueFalse"); // style
Expand Down Expand Up @@ -1783,7 +1785,7 @@ void CheckCondition::pointerAdditionResultNotNullError(const Token *tok, const T

void CheckCondition::checkDuplicateConditionalAssign()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("duplicateConditionalAssign"))
return;

logChecker("CheckCondition::checkDuplicateConditionalAssign"); // style
Expand Down Expand Up @@ -1862,7 +1864,7 @@ void CheckCondition::duplicateConditionalAssignError(const Token *condTok, const

void CheckCondition::checkAssignmentInCondition()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("assignmentInCondition"))
return;

logChecker("CheckCondition::checkAssignmentInCondition"); // style
Expand Down Expand Up @@ -1909,7 +1911,7 @@ void CheckCondition::assignmentInCondition(const Token *eq)

void CheckCondition::checkCompareValueOutOfTypeRange()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("compareValueOutOfTypeRange"))
return;

if (mSettings->platform.type == Platform::Type::Native ||
Expand Down
7 changes: 4 additions & 3 deletions lib/checkexceptionsafety.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void CheckExceptionSafety::deallocThrowError(const Token * const tok, const std:
//---------------------------------------------------------------------------
void CheckExceptionSafety::checkRethrowCopy()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("rethrowcopy"))
return;

logChecker("CheckExceptionSafety::checkRethrowCopy"); // style
Expand Down Expand Up @@ -213,7 +213,7 @@ void CheckExceptionSafety::rethrowCopyError(const Token * const tok, const std::
//---------------------------------------------------------------------------
void CheckExceptionSafety::checkCatchExceptionByValue()
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("catchexceptionbyvalue"))
return;

logChecker("CheckExceptionSafety::checkCatchExceptionByValue"); // style
Expand Down Expand Up @@ -329,7 +329,8 @@ void CheckExceptionSafety::noexceptThrowError(const Token * const tok)
//--------------------------------------------------------------------------
void CheckExceptionSafety::unhandledExceptionSpecification()
{
if (!mSettings->severity.isEnabled(Severity::style) || !mSettings->certainty.isEnabled(Certainty::inconclusive))
if ((!mSettings->severity.isEnabled(Severity::style) || !mSettings->certainty.isEnabled(Certainty::inconclusive)) &&
!mSettings->isPremiumEnabled("unhandledexceptionspecification"))
return;

logChecker("CheckExceptionSafety::unhandledExceptionSpecification"); // style,inconclusive
Expand Down
6 changes: 4 additions & 2 deletions lib/checkfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ void CheckFunctions::invalidFunctionArgStrError(const Token *tok, const std::str
//---------------------------------------------------------------------------
void CheckFunctions::checkIgnoredReturnValue()
{
if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::warning) &&
!mSettings->severity.isEnabled(Severity::style) &&
!mSettings->isPremiumEnabled("ignoredReturnValue"))
return;

logChecker("CheckFunctions::checkIgnoredReturnValue"); // style,warning
Expand Down Expand Up @@ -424,7 +426,7 @@ void CheckFunctions::checkMathFunctions()
const bool styleC99 = mSettings->severity.isEnabled(Severity::style) && mSettings->standards.c != Standards::C89 && mSettings->standards.cpp != Standards::CPP03;
const bool printWarnings = mSettings->severity.isEnabled(Severity::warning);

if (!styleC99 && !printWarnings)
if (!styleC99 && !printWarnings && !mSettings->isPremiumEnabled("wrongmathcall"))
return;

logChecker("CheckFunctions::checkMathFunctions"); // style,warning,c99,c++11
Expand Down
2 changes: 1 addition & 1 deletion lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam

void CheckMemoryLeakInClass::unsafeClassError(const Token *tok, const std::string &classname, const std::string &varname)
{
if (!mSettings->severity.isEnabled(Severity::style))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("unsafeClassCanLeak"))
return;

reportError(tok, Severity::style, "unsafeClassCanLeak",
Expand Down
Loading

0 comments on commit 309aa8a

Please sign in to comment.