Skip to content

Commit

Permalink
Fix #12710 (Checkers report: update premium checkers info) (danmar#6360)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar authored May 5, 2024
1 parent 665cfce commit 50be22d
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 39 deletions.
2 changes: 1 addition & 1 deletion lib/checkbool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void CheckBool::assignBoolToPointerError(const Token *tok)
//-----------------------------------------------------------------------------
void CheckBool::checkComparisonOfBoolExpressionWithInt()
{
if (!mSettings->severity.isEnabled(Severity::warning))
if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("compareBoolExpressionWithInt"))
return;

logChecker("CheckBool::checkComparisonOfBoolExpressionWithInt"); // warning
Expand Down
4 changes: 2 additions & 2 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ void CheckClass::operatorEqMissingReturnStatementError(const Token *tok, bool er

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

logChecker("CheckClass::operatorEqToSelf"); // warning
Expand Down Expand Up @@ -2953,7 +2953,7 @@ void CheckClass::pureVirtualFunctionCallInConstructorError(

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

logChecker("CheckClass::checkDuplInheritedMembers"); // warning
Expand Down
7 changes: 5 additions & 2 deletions lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,9 @@ static bool isNonConstFunctionCall(const Token *ftok, const Library &library)

void CheckCondition::multiCondition2()
{
if (!mSettings->severity.isEnabled(Severity::warning))
if (!mSettings->severity.isEnabled(Severity::warning) &&
!mSettings->isPremiumEnabled("identicalConditionAfterEarlyExit") &&
!mSettings->isPremiumEnabled("identicalInnerCondition"))
return;

logChecker("CheckCondition::multiCondition2"); // warning
Expand Down Expand Up @@ -1482,7 +1484,8 @@ void CheckCondition::alwaysTrueFalse()
{
if (!mSettings->severity.isEnabled(Severity::style) &&
!mSettings->isPremiumEnabled("alwaysTrue") &&
!mSettings->isPremiumEnabled("alwaysFalse"))
!mSettings->isPremiumEnabled("alwaysFalse") &&
!mSettings->isPremiumEnabled("knownConditionTrueFalse"))
return;

logChecker("CheckCondition::alwaysTrueFalse"); // style
Expand Down
96 changes: 93 additions & 3 deletions lib/checkers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ namespace checkers {
{"CheckOther::checkUnreachableCode","style"},
{"CheckOther::checkVariableScope","style,notclang"},
{"CheckOther::checkPassByReference","performance,c++"},
{"CheckOther::checkConstVariable","style,c++"},
{"CheckOther::checkConstPointer","style"},
{"CheckOther::checkCharVariable","warning,portability"},
{"CheckOther::checkIncompleteStatement","warning"},
Expand Down Expand Up @@ -146,6 +147,7 @@ namespace checkers {
{"CheckUnusedVar::checkStructMemberUsage","style"},
{"CheckIO::checkCoutCerrMisusage","c"},
{"CheckIO::checkFileUsage",""},
{"CheckIO::invalidScanf",""},
{"CheckIO::checkWrongPrintfScanfArguments",""},
{"CheckCondition::assignIf","style"},
{"CheckCondition::checkBadBitmaskCheck","style"},
Expand Down Expand Up @@ -202,6 +204,7 @@ namespace checkers {
{"CheckMemoryLeakInClass::check",""},
{"CheckMemoryLeakStructMember::check",""},
{"CheckMemoryLeakNoVar::check",""},
{"CheckMemoryLeakNoVar::checkForUnsafeArgAlloc",""},
};

const std::map<std::string, std::string> premiumCheckers{
Expand Down Expand Up @@ -230,7 +233,6 @@ namespace checkers {
{"Autosar: A2-13-1",""},
{"Autosar: A2-13-3",""},
{"Autosar: A2-13-5",""},
{"Autosar: A2-13-6",""},
{"Autosar: A2-5-2",""},
{"Autosar: A20-8-2","warning"},
{"Autosar: A20-8-3","warning"},
Expand Down Expand Up @@ -404,6 +406,9 @@ namespace checkers {
{"Cert C: STR32-C",""},
{"Cert C: STR34-C",""},
{"Cert C: STR38-C",""},
{"Misra C++ 2008: 3-2-3",""},
{"Misra C++ 2008: 3-2-4",""},
{"Misra C++ 2008: 7-5-4",""},
{"Misra C++ 2008: M0-1-11",""},
{"Misra C++ 2008: M0-1-12",""},
{"Misra C++ 2008: M0-1-4",""},
Expand Down Expand Up @@ -578,55 +583,115 @@ namespace checkers {
{"Misra C++ 2008: M9-6-2",""},
{"Misra C++ 2008: M9-6-3",""},
{"Misra C++ 2008: M9-6-4",""},
{"Misra C++ 2023: 0.1.2",""},
{"Misra C++ 2023: 0.2.1",""},
{"Misra C++ 2023: 0.2.2",""},
{"Misra C++ 2023: 0.2.3",""},
{"Misra C++ 2023: 0.2.4",""},
{"Misra C++ 2023: 10.0.1",""},
{"Misra C++ 2023: 10.1.2",""},
{"Misra C++ 2023: 10.2.1",""},
{"Misra C++ 2023: 10.2.2",""},
{"Misra C++ 2023: 10.2.3",""},
{"Misra C++ 2023: 10.3.1",""},
{"Misra C++ 2023: 10.4.1",""},
{"Misra C++ 2023: 11.3.1",""},
{"Misra C++ 2023: 11.3.2",""},
{"Misra C++ 2023: 11.6.1",""},
{"Misra C++ 2023: 11.6.3",""},
{"Misra C++ 2023: 12.2.1",""},
{"Misra C++ 2023: 12.2.2",""},
{"Misra C++ 2023: 12.2.3",""},
{"Misra C++ 2023: 12.3.1",""},
{"Misra C++ 2023: 13.1.1",""},
{"Misra C++ 2023: 13.1.2",""},
{"Misra C++ 2023: 13.3.1",""},
{"Misra C++ 2023: 13.3.2",""},
{"Misra C++ 2023: 13.3.3",""},
{"Misra C++ 2023: 13.3.4",""},
{"Misra C++ 2023: 14.1.1",""},
{"Misra C++ 2023: 15.0.1",""},
{"Misra C++ 2023: 15.0.2",""},
{"Misra C++ 2023: 15.1.2",""},
{"Misra C++ 2023: 15.1.3",""},
{"Misra C++ 2023: 15.1.5",""},
{"Misra C++ 2023: 16.5.1",""},
{"Misra C++ 2023: 16.5.2",""},
{"Misra C++ 2023: 16.6.1",""},
{"Misra C++ 2023: 17.8.1",""},
{"Misra C++ 2023: 18.1.1",""},
{"Misra C++ 2023: 18.1.2",""},
{"Misra C++ 2023: 18.3.1",""},
{"Misra C++ 2023: 18.3.2",""},
{"Misra C++ 2023: 18.3.3",""},
{"Misra C++ 2023: 18.4.1",""},
{"Misra C++ 2023: 18.5.1",""},
{"Misra C++ 2023: 18.5.2",""},
{"Misra C++ 2023: 19.0.1",""},
{"Misra C++ 2023: 19.0.2",""},
{"Misra C++ 2023: 19.0.3",""},
{"Misra C++ 2023: 19.0.4",""},
{"Misra C++ 2023: 19.1.1",""},
{"Misra C++ 2023: 19.1.2",""},
{"Misra C++ 2023: 19.1.3",""},
{"Misra C++ 2023: 19.2.1",""},
{"Misra C++ 2023: 19.2.2",""},
{"Misra C++ 2023: 19.2.3",""},
{"Misra C++ 2023: 19.3.1",""},
{"Misra C++ 2023: 19.3.2",""},
{"Misra C++ 2023: 19.3.3",""},
{"Misra C++ 2023: 21.20.1",""},
{"Misra C++ 2023: 21.20.2",""},
{"Misra C++ 2023: 19.3.4",""},
{"Misra C++ 2023: 19.6.1",""},
{"Misra C++ 2023: 21.10.1",""},
{"Misra C++ 2023: 21.10.2",""},
{"Misra C++ 2023: 21.10.3",""},
{"Misra C++ 2023: 21.2.1",""},
{"Misra C++ 2023: 21.2.2",""},
{"Misra C++ 2023: 21.2.3",""},
{"Misra C++ 2023: 21.2.4",""},
{"Misra C++ 2023: 21.6.1",""},
{"Misra C++ 2023: 21.6.2",""},
{"Misra C++ 2023: 21.6.3",""},
{"Misra C++ 2023: 21.6.4",""},
{"Misra C++ 2023: 21.6.5",""},
{"Misra C++ 2023: 22.3.1",""},
{"Misra C++ 2023: 22.4.1",""},
{"Misra C++ 2023: 23.11.1",""},
{"Misra C++ 2023: 24.5.1",""},
{"Misra C++ 2023: 24.5.2",""},
{"Misra C++ 2023: 25.5.1",""},
{"Misra C++ 2023: 25.5.2",""},
{"Misra C++ 2023: 25.5.3",""},
{"Misra C++ 2023: 26.3.1",""},
{"Misra C++ 2023: 28.3.1",""},
{"Misra C++ 2023: 28.6.1",""},
{"Misra C++ 2023: 28.6.2",""},
{"Misra C++ 2023: 30.0.1",""},
{"Misra C++ 2023: 30.0.2",""},
{"Misra C++ 2023: 4.1.1",""},
{"Misra C++ 2023: 4.1.2",""},
{"Misra C++ 2023: 5.0.1",""},
{"Misra C++ 2023: 5.13.1",""},
{"Misra C++ 2023: 5.13.2",""},
{"Misra C++ 2023: 5.13.3",""},
{"Misra C++ 2023: 5.13.4",""},
{"Misra C++ 2023: 5.13.5",""},
{"Misra C++ 2023: 5.13.6",""},
{"Misra C++ 2023: 5.13.7",""},
{"Misra C++ 2023: 5.7.1",""},
{"Misra C++ 2023: 5.7.2",""},
{"Misra C++ 2023: 5.7.3",""},
{"Misra C++ 2023: 6.0.1",""},
{"Misra C++ 2023: 6.0.2",""},
{"Misra C++ 2023: 6.0.3",""},
{"Misra C++ 2023: 6.0.4",""},
{"Misra C++ 2023: 6.2.2",""},
{"Misra C++ 2023: 6.2.3",""},
{"Misra C++ 2023: 6.2.4",""},
{"Misra C++ 2023: 6.4.2",""},
{"Misra C++ 2023: 6.4.3",""},
{"Misra C++ 2023: 6.5.1",""},
{"Misra C++ 2023: 6.5.2",""},
{"Misra C++ 2023: 6.7.1",""},
{"Misra C++ 2023: 6.7.2",""},
{"Misra C++ 2023: 6.8.3",""},
Expand All @@ -636,20 +701,42 @@ namespace checkers {
{"Misra C++ 2023: 7.0.1",""},
{"Misra C++ 2023: 7.0.2",""},
{"Misra C++ 2023: 7.0.3",""},
{"Misra C++ 2023: 7.0.4",""},
{"Misra C++ 2023: 7.0.5",""},
{"Misra C++ 2023: 7.0.6",""},
{"Misra C++ 2023: 7.11.1",""},
{"Misra C++ 2023: 7.11.2",""},
{"Misra C++ 2023: 7.11.3",""},
{"Misra C++ 2023: 8.0.1",""},
{"Misra C++ 2023: 8.1.1",""},
{"Misra C++ 2023: 8.1.2",""},
{"Misra C++ 2023: 8.14.1",""},
{"Misra C++ 2023: 8.18.2",""},
{"Misra C++ 2023: 8.19.1",""},
{"Misra C++ 2023: 8.2.1",""},
{"Misra C++ 2023: 8.2.10",""},
{"Misra C++ 2023: 8.2.11",""},
{"Misra C++ 2023: 8.2.2",""},
{"Misra C++ 2023: 8.2.3",""},
{"Misra C++ 2023: 8.2.4",""},
{"Misra C++ 2023: 8.2.5",""},
{"Misra C++ 2023: 8.2.6",""},
{"Misra C++ 2023: 8.2.7",""},
{"Misra C++ 2023: 8.2.8",""},
{"Misra C++ 2023: 8.2.9",""},
{"Misra C++ 2023: 8.20.1",""},
{"Misra C++ 2023: 8.3.1",""},
{"Misra C++ 2023: 8.3.2",""},
{"Misra C++ 2023: 9.2.1",""},
{"Misra C++ 2023: 9.3.1",""},
{"Misra C++ 2023: 9.4.1",""},
{"Misra C++ 2023: 9.4.2",""},
{"Misra C++ 2023: 9.5.1",""},
{"Misra C++ 2023: 9.5.2",""},
{"Misra C++ 2023: 9.6.1",""},
{"Misra C++ 2023: 9.6.2",""},
{"Misra C++ 2023: 9.6.3",""},
{"Misra C++ 2023: 9.6.4",""},
{"Misra C: 1.4",""},
{"Misra C: 1.5",""},
{"Misra C: 10.1",""},
Expand All @@ -675,6 +762,7 @@ namespace checkers {
{"Misra C: 17.11",""},
{"Misra C: 17.12",""},
{"Misra C: 17.13",""},
{"Misra C: 17.2",""},
{"Misra C: 17.3",""},
{"Misra C: 17.4",""},
{"Misra C: 17.9",""},
Expand Down Expand Up @@ -720,6 +808,8 @@ namespace checkers {
{"Misra C: 8.17",""},
{"Misra C: 8.3",""},
{"Misra C: 8.4",""},
{"Misra C: 8.6",""},
{"Misra C: 8.7",""},
{"Misra C: 8.8",""},
{"Misra C: 9.6",""},
{"Misra C: 9.7",""},
Expand Down
10 changes: 6 additions & 4 deletions lib/checkio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,11 @@ void CheckIO::incompatibleFileOpenError(const Token *tok, const std::string &fil
//---------------------------------------------------------------------------
void CheckIO::invalidScanf()
{
if (!mSettings->severity.isEnabled(Severity::warning))
if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("invalidscanf"))
return;

logChecker("CheckIO::invalidScanf");

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()) {
Expand Down Expand Up @@ -1710,7 +1712,7 @@ void CheckIO::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))
if (severity != Severity::error && !mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("wrongPrintfScanfArgNum"))
return;

std::ostringstream errmsg;
Expand All @@ -1729,7 +1731,7 @@ void CheckIO::wrongPrintfScanfArgumentsError(const Token* tok,
void CheckIO::wrongPrintfScanfPosixParameterPositionError(const Token* tok, const std::string& functionName,
nonneg int index, nonneg int numFunction)
{
if (!mSettings->severity.isEnabled(Severity::warning))
if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("wrongPrintfScanfParameterPositionError"))
return;
std::ostringstream errmsg;
errmsg << functionName << ": ";
Expand Down Expand Up @@ -1992,7 +1994,7 @@ void CheckIO::argumentType(std::ostream& os, const ArgumentInfo * argInfo)

void CheckIO::invalidLengthModifierError(const Token* tok, nonneg int numFormat, const std::string& modifier)
{
if (!mSettings->severity.isEnabled(Severity::warning))
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.";
Expand Down
7 changes: 6 additions & 1 deletion lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1093,9 +1093,14 @@ void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope)
void CheckMemoryLeakNoVar::checkForUnsafeArgAlloc(const Scope *scope)
{
// This test only applies to C++ source
if (!mTokenizer->isCPP() || !mSettings->certainty.isEnabled(Certainty::inconclusive) || !mSettings->severity.isEnabled(Severity::warning))
if (!mTokenizer->isCPP())
return;

if (!mSettings->isPremiumEnabled("leakUnsafeArgAlloc") && (!mSettings->certainty.isEnabled(Certainty::inconclusive) || !mSettings->severity.isEnabled(Severity::warning)))
return;

logChecker("CheckMemoryLeakNoVar::checkForUnsafeArgAlloc");

for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
if (Token::Match(tok, "%name% (")) {
const Token *endParamToken = tok->next()->link();
Expand Down
2 changes: 1 addition & 1 deletion lib/checknullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ void CheckNullPointer::nullPointerError(const Token *tok, const std::string &var
return;
}

if (!mSettings->isEnabled(value, inconclusive))
if (!mSettings->isEnabled(value, inconclusive) && !mSettings->isPremiumEnabled("nullPointer"))
return;

const ErrorPath errorPath = getErrorPath(tok, value, "Null pointer dereference");
Expand Down
15 changes: 11 additions & 4 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ void CheckOther::invalidPointerCastError(const Token* tok, const std::string& fr

void CheckOther::checkRedundantAssignment()
{
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("redundantAssignment"))
if (!mSettings->severity.isEnabled(Severity::style) &&
!mSettings->isPremiumEnabled("redundantAssignment") &&
!mSettings->isPremiumEnabled("redundantAssignInSwitch"))
return;

logChecker("CheckOther::checkRedundantAssignment"); // style
Expand Down Expand Up @@ -773,7 +775,7 @@ void CheckOther::checkUnreachableCode()
// misra-c-2023-2.1
// misra-cpp-2008-0-1-1
// autosar
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("unreachableCode"))
if (!mSettings->severity.isEnabled(Severity::style) && !mSettings->isPremiumEnabled("duplicateBreak") && !mSettings->isPremiumEnabled("unreachableCode"))
return;

logChecker("CheckOther::checkUnreachableCode"); // style
Expand Down Expand Up @@ -1326,9 +1328,11 @@ static bool isVariableMutableInInitializer(const Token* start, const Token * end

void CheckOther::checkConstVariable()
{
if (!mSettings->severity.isEnabled(Severity::style) || mTokenizer->isC())
if ((!mSettings->severity.isEnabled(Severity::style) || mTokenizer->isC()) && !mSettings->isPremiumEnabled("constVariable"))
return;

logChecker("CheckOther::checkConstVariable"); // style,c++

const SymbolDatabase *const symbolDatabase = mTokenizer->getSymbolDatabase();

for (const Variable *var : symbolDatabase->variableList()) {
Expand Down Expand Up @@ -1476,6 +1480,7 @@ void CheckOther::checkConstPointer()
{
if (!mSettings->severity.isEnabled(Severity::style) &&
!mSettings->isPremiumEnabled("constParameter") &&
!mSettings->isPremiumEnabled("constParameterReference") &&
!mSettings->isPremiumEnabled("constPointer"))
return;

Expand Down Expand Up @@ -3344,7 +3349,9 @@ void CheckOther::unknownEvaluationOrder(const Token* tok)

void CheckOther::checkAccessOfMovedVariable()
{
if (!mTokenizer->isCPP() || mSettings->standards.cpp < Standards::CPP11 || !mSettings->severity.isEnabled(Severity::warning))
if (!mTokenizer->isCPP() || mSettings->standards.cpp < Standards::CPP11)
return;
if (!mSettings->isPremiumEnabled("accessMoved") && !mSettings->severity.isEnabled(Severity::warning))
return;
logChecker("CheckOther::checkAccessOfMovedVariable"); // c++11,warning
const bool reportInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive);
Expand Down
2 changes: 1 addition & 1 deletion lib/checksizeof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void CheckSizeof::sizeofCalculationError(const Token *tok, bool inconclusive)

void CheckSizeof::sizeofFunction()
{
if (!mSettings->severity.isEnabled(Severity::warning))
if (!mSettings->severity.isEnabled(Severity::warning) && !mSettings->isPremiumEnabled("sizeofFunctionCall"))
return;

logChecker("CheckSizeof::sizeofFunction"); // warning
Expand Down
Loading

0 comments on commit 50be22d

Please sign in to comment.