Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

settings.cpp: Update autosar+cert+misra checkers mappings #5933

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 192 additions & 62 deletions lib/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,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 @@ -274,122 +279,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;
}
Loading