Skip to content

Commit

Permalink
settings.cpp: Update autosar+cert+misra checkers mappings (#5933)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Feb 1, 2024
1 parent a1f4a23 commit 02832e1
Showing 1 changed file with 192 additions and 62 deletions.
254 changes: 192 additions & 62 deletions lib/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,19 @@ void Settings::setCheckLevelNormal()

// TODO: auto generate these tables

static const std::set<std::string> autosar_checkers{
static const std::set<std::string> autosarCheckers{
"accessMoved",
"argumentSize",
"arrayIndexOutOfBounds",
"arrayIndexOutOfBoundsCond",
"arrayIndexThenCheck",
"bufferAccessOutOfBounds",
"comparePointers",
"constParameter",
"cstyleCast",
"ctuOneDefinitionViolation",
"doubleFree",
"duplInheritedMember",
"duplicateBreak",
"funcArgNamesDifferent",
"functionConst",
Expand All @@ -272,122 +277,247 @@ static const std::set<std::string> autosar_checkers{
"memleak",
"mismatchAllocDealloc",
"missingReturn",
"negativeIndex",
"noExplicitConstructor",
"nullPointer",
"nullPointerArithmetic",
"nullPointerArithmeticRedundantCheck",
"nullPointerDefaultArg",
"nullPointerRedundantCheck",
"objectIndex",
"overlappingWriteFunction",
"overlappingWriteUnion",
"pointerOutOfBounds",
"unreadVariable",
"unusedValue",
"pointerOutOfBoundsCond",
"preprocessorErrorDirective",
"redundantAssignment",
"redundantInitialization",
"returnDanglingLifetime",
"shadowVariable",
"shiftTooManyBits",
"sizeofSideEffects",
"throwInDestructor",
"throwInNoexceptFunction",
"unreachableCode",
"uninitData",
"uninitMember",
"unreachableCode",
"unreadVariable",
"unsignedLessThanZero",
"unusedFunction",
"unusedStructMember",
"unusedValue",
"unusedVariable",
"useInitializerList",
"variableScope",
"virtualCallInConstructor",
"zeroDiv"
"zerodiv",
"zerodivcond"
};

static const std::set<std::string> cert_c_checkers{
"danglingLifetime", "autoVariables", "invalidLifetime",
"unknownEvaluationOrder",
"uninitvar", "uninitdata", "uninitStructMember",
"nullPointer",
"sizeofCalculation",
static const std::set<std::string> certCCheckers{
"IOWithoutPositioning",
"autoVariables",
"autovarInvalidDeallocation",
"bitwiseOnBoolean",
"invalidFunctionArg",
"floatConversionOverflow",
"comparePointers",
"stringLiteralWrite",
"doubleFree",
"danglingLifetime",
"deallocret",
"deallocuse",
"doubleFree",
"floatConversionOverflow",
"invalidFunctionArg",
"invalidLengthModifierError",
"invalidLifetime",
"invalidScanfFormatWidth",
"invalidscanf",
"leakReturnValNotUsed",
"leakUnsafeArgAlloc",
"memleak",
"autovarInvalidDeallocation",
"memleakOnRealloc",
"mismatchAllocDealloc",
"IOWithoutPositioning",
"missingReturn",
"nullPointer",
"nullPointerArithmetic",
"nullPointerArithmeticRedundantCheck",
"nullPointerDefaultArg",
"nullPointerRedundantCheck",
"preprocessorErrorDirective",
"resourceLeak",
"sizeofCalculation",
"stringLiteralWrite",
"uninitStructMember",
"uninitdata",
"uninitvar",
"unknownEvaluationOrder",
"useClosedFile",
"invalidscanf",
"wrongPrintfScanfArgNum",
"invalidLengthModifierError",
"invalidScanfFormatWidth",
"wrongPrintfScanfParameterPositionError",
"missingReturn"
"wrongPrintfScanfParameterPositionError"
};

static const std::set<std::string> cert_cpp_checkers{
"deallocThrow", "exceptThrowInDestructor",
"ctuOneDefinitionViolation",
"sizeofCalculation",
"comparePointers",
static const std::set<std::string> certCppCheckers{
"IOWithoutPositioning",
"virtualCallInConstructor",
"virtualDestructor",
"accessMoved",
"comparePointers",
"containerOutOfBounds",
"ctuOneDefinitionViolation",
"deallocMismatch",
"deallocThrow",
"deallocuse",
"doubleFree",
"eraseDereference",
"exceptThrowInDestructor",
"initializerList",
"operatorEqToSelf",
"invalidContainer",
"lifetime",
"memleak",
"missingReturn",
"nullPointer",
"operatorEqToSelf",
"sizeofCalculation",
"uninitvar",
"virtualCallInConstructor",
"virtualDestructor"
};

static const std::set<std::string> misra_c_checkers{
"alwaysFalse", "duplicateBreak",
"alwaysTrue", "redundantCondition", "redundantAssignment", "redundantAssignInSwitch", "unreadVariable",
"unusedVariable",
"unusedLabel",
"shadowVariable",
"funcArgNamesDifferent",
static const std::set<std::string> misrac2012Checkers{
"alwaysFalse",
"alwaysTrue",
"argumentSize",
"autovarInvalidDeallocation",
"bufferAccessOutOfBounds",
"comparePointers",
"compareValueOutOfTypeRangeError",
"constPointer",
"danglingLifetime",
"duplicateBreak",
"error",
"funcArgNamesDifferent",
"incompatibleFileOpen",
"invalidFunctionArg",
"knownConditionTrueFalse",
"leakNoVarFunctionCall",
"leakReturnValNotUsed",
"memleak",
"memleakOnRealloc",
"missingReturn",
"overlappingWriteFunction",
"overlappingWriteUnion",
"pointerOutOfBounds",
"preprocessorErrorDirective",
"redundantAssignInSwitch",
"redundantAssignment",
"redundantCondition",
"resourceLeak",
"shadowVariable",
"sizeofCalculation",
"syntaxError",
"uninitvar",
"alwaysTrue", "alwaysFalse", "compareValueOutOfTypeRangeError", "knownConditionTrueFalse",
"unknownEvaluationOrder",
"sizeofCalculation",
"missingReturn",
"unreadVariable",
"unusedLabel",
"unusedVariable",
"useClosedFile",
"writeReadOnlyFile"
};

static const std::set<std::string> misrac2023Checkers{
"alwaysFalse",
"alwaysTrue",
"argumentSize",
"pointerOutOfBounds",
"autovarInvalidDeallocation",
"bufferAccessOutOfBounds",
"comparePointers",
"compareValueOutOfTypeRangeError",
"constPointer",
"danglingLifetime",
"overlappingWriteUnion", "overlappingWriteFunction",
"invalidFunctionArg",
"bufferAccessOutOfBounds",
"memleak", "resourceLeak", "memleakOnRealloc", "leakReturnValNotUsed", "leakNoVarFunctionCall",
"autovarInvalidDeallocation",
"duplicateBreak",
"error",
"funcArgNamesDifferent",
"incompatibleFileOpen",
"writeReadOnlyFile",
"useClosedFile"
};

static const std::set<std::string> misra_cpp_checkers{
"redundantAssignment", "unreadVariable", "varScope",
"invalidFunctionArg",
"knownConditionTrueFalse",
"leakNoVarFunctionCall",
"leakReturnValNotUsed",
"memleak",
"memleakOnRealloc",
"missingReturn",
"overlappingWriteFunction",
"overlappingWriteUnion",
"pointerOutOfBounds",
"preprocessorErrorDirective",
"redundantAssignInSwitch",
"redundantAssignment",
"redundantCondition",
"resourceLeak",
"shadowVariable",
"sizeofCalculation",
"syntaxError",
"uninitvar",
"unknownEvaluationOrder",
"unreadVariable",
"unusedLabel",
"unusedVariable",
"useClosedFile",
"writeReadOnlyFile"
};

static const std::set<std::string> misracpp2008Checkers{
"autoVariables",
"comparePointers",
"constParameter",
"constVariable",
"cstyleCast",
"constVariable", "constParameter",
"ctuOneDefinitionViolation",
"danglingLifetime",
"duplInheritedMember",
"duplicateBreak",
"exceptThrowInDestructor",
"funcArgNamesDifferent",
"functionConst",
"functionStatic",
"missingReturn",
"uninitMember",
"noExplicit",
"exceptThrowInDestructor",
"throwInDestructor"
"overlappingWriteFunction",
"overlappingWriteUnion",
"pointerOutOfBounds",
"preprocessorErrorDirective",
"redundantAssignment",
"redundantInitialization",
"returnReference",
"returnTempReference",
"shadowVariable",
"shiftTooManyBits",
"sizeofSideEffects",
"throwInDestructor",
"uninitDerivedMemberVar",
"uninitDerivedMemberVarPrivate",
"uninitMemberVar",
"uninitMemberVarPrivate",
"uninitStructMember",
"uninitdata",
"uninitvar",
"unknownEvaluationOrder",
"unreachableCode",
"unreadVariable",
"unsignedLessThanZero",
"unusedFunction",
"unusedStructMember",
"unusedVariable",
"varScope",
"variableScope",
"virtualCallInConstructor"
};

bool Settings::isPremiumEnabled(const char id[]) const
{
if (premiumArgs.find("autosar") != std::string::npos && autosar_checkers.count(id))
if (premiumArgs.find("autosar") != std::string::npos && autosarCheckers.count(id))
return true;
if (premiumArgs.find("cert-c-") != std::string::npos && cert_c_checkers.count(id))
if (premiumArgs.find("cert-c-") != std::string::npos && certCCheckers.count(id))
return true;
if (premiumArgs.find("cert-c++") != std::string::npos && cert_cpp_checkers.count(id))
if (premiumArgs.find("cert-c++") != std::string::npos && certCppCheckers.count(id))
return true;
if (premiumArgs.find("misra-c-") != std::string::npos && misra_c_checkers.count(id))
if (premiumArgs.find("misra-c-") != std::string::npos && (misrac2012Checkers.count(id) || misrac2023Checkers.count(id)))
return true;
if (premiumArgs.find("misra-c++") != std::string::npos && misra_cpp_checkers.count(id))
if (premiumArgs.find("misra-c++") != std::string::npos && misracpp2008Checkers.count(id))
return true;
return false;
}

0 comments on commit 02832e1

Please sign in to comment.