From 782094003cd1257dcbbed17395a170c6b588c159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 1 Feb 2024 10:44:57 +0100 Subject: [PATCH] settings.cpp: Update autosar+cert+misra checkers mappings --- lib/settings.cpp | 254 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 192 insertions(+), 62 deletions(-) diff --git a/lib/settings.cpp b/lib/settings.cpp index 0fd99ace212..6ded3497e4e 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -258,14 +258,19 @@ void Settings::setCheckLevelNormal() // TODO: auto generate these tables -static const std::set autosar_checkers{ +static const std::set autosarCheckers{ "accessMoved", + "argumentSize", "arrayIndexOutOfBounds", + "arrayIndexOutOfBoundsCond", + "arrayIndexThenCheck", + "bufferAccessOutOfBounds", "comparePointers", "constParameter", "cstyleCast", "ctuOneDefinitionViolation", "doubleFree", + "duplInheritedMember", "duplicateBreak", "funcArgNamesDifferent", "functionConst", @@ -274,122 +279,247 @@ static const std::set 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 cert_c_checkers{ - "danglingLifetime", "autoVariables", "invalidLifetime", - "unknownEvaluationOrder", - "uninitvar", "uninitdata", "uninitStructMember", - "nullPointer", - "sizeofCalculation", +static const std::set 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 cert_cpp_checkers{ - "deallocThrow", "exceptThrowInDestructor", - "ctuOneDefinitionViolation", - "sizeofCalculation", - "comparePointers", +static const std::set 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 misra_c_checkers{ - "alwaysFalse", "duplicateBreak", - "alwaysTrue", "redundantCondition", "redundantAssignment", "redundantAssignInSwitch", "unreadVariable", - "unusedVariable", - "unusedLabel", - "shadowVariable", - "funcArgNamesDifferent", +static const std::set 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 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 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 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; }