68     static const std::string cfgFilename = 
"cppcheck.cfg";
 
   75     if (fileName.empty()) {
 
   82     std::ifstream fin(fileName);
 
   84         return "could not open file";
 
   88         const std::string& lastErr = picojson::get_last_error();
 
   90             return "not a valid JSON - " + lastErr;
 
   92     const picojson::object& obj = json.get<picojson::object>();
 
   94         const picojson::object::const_iterator it = obj.find(
"productName");
 
   95         if (it != obj.cend()) {
 
   96             const auto& v = it->second;
 
   97             if (!v.is<std::string>())
 
   98                 return "'productName' is not a string";
 
  103         const picojson::object::const_iterator it = obj.find(
"about");
 
  104         if (it != obj.cend()) {
 
  105             const auto& v = it->second;
 
  106             if (!v.is<std::string>())
 
  107                 return "'about' is not a string";
 
  112         const picojson::object::const_iterator it = obj.find(
"addons");
 
  113         if (it != obj.cend()) {
 
  114             const auto& entry = it->second;
 
  115             if (!entry.is<picojson::array>())
 
  116                 return "'addons' is not an array";
 
  117             for (
const picojson::value &v : entry.get<picojson::array>())
 
  119                 if (!v.is<std::string>())
 
  120                     return "'addons' array entry is not a string";
 
  121                 const std::string &s = v.get<std::string>();
 
  125                     settings.
addons.emplace(s);
 
  130         const picojson::object::const_iterator it = obj.find(
"suppressions");
 
  131         if (it != obj.cend()) {
 
  132             const auto& entry = it->second;
 
  133             if (!entry.is<picojson::array>())
 
  134                 return "'suppressions' is not an array";
 
  135             for (
const picojson::value &v : entry.get<picojson::array>())
 
  137                 if (!v.is<std::string>())
 
  138                     return "'suppressions' array entry is not a string";
 
  139                 const std::string &s = v.get<std::string>();
 
  142                     return "could not parse suppression '" + s + 
"' - " + err;
 
  147         const picojson::object::const_iterator it = obj.find(
"safety");
 
  148         if (it != obj.cend()) {
 
  149             const auto& v = it->second;
 
  151                 return "'safety' is not a bool";
 
  160     if (productName.empty())
 
  162     const std::string::size_type pos1 = productName.rfind(
' ');
 
  163     if (pos1 == std::string::npos)
 
  165     if (pos1 + 2 >= productName.length())
 
  167     for (
auto pos2 = pos1 + 1; pos2 < productName.length(); ++pos2) {
 
  168         const char c = productName[pos2];
 
  169         const char prev = productName[pos2-1];
 
  172         if (c == 
'.' && std::isdigit(prev))
 
  174         if (c == 
's' && pos2 + 1 == productName.length() && std::isdigit(prev))
 
  178     return {productName.substr(0, pos1), productName.substr(pos1+1)};
 
  184     if (str.find(
',') != std::string::npos) {
 
  185         std::string::size_type prevPos = 0;
 
  186         std::string::size_type pos = 0;
 
  187         while ((pos = str.find(
',', pos)) != std::string::npos) {
 
  189                 return std::string(
"--enable parameter is empty");
 
  190             std::string errmsg(
parseEnabled(str.substr(prevPos, pos - prevPos), groups));
 
  196         if (prevPos >= str.length())
 
  197             return std::string(
"--enable parameter is empty");
 
  201     auto& 
severity = std::get<0>(groups);
 
  202     auto& 
checks = std::get<1>(groups);
 
  212     } 
else if (str == 
"warning") {
 
  214     } 
else if (str == 
"style") {
 
  216     } 
else if (str == 
"performance") {
 
  218     } 
else if (str == 
"portability") {
 
  220     } 
else if (str == 
"information") {
 
  222     } 
else if (str == 
"unusedFunction") {
 
  224     } 
else if (str == 
"missingInclude") {
 
  227 #ifdef CHECK_INTERNAL 
  228     else if (str == 
"internal") {
 
  235             return " parameter is empty";
 
  236         return " parameter with the unknown name '" + str + 
"'";
 
  257         return (enable ? 
"--enable" : 
"--disable") + errmsg;
 
  259     const auto s = std::get<0>(groups);
 
  260     const auto c = std::get<1>(groups);
 
  309     "arrayIndexOutOfBounds",
 
  310     "arrayIndexOutOfBoundsCond",
 
  311     "arrayIndexThenCheck",
 
  312     "bufferAccessOutOfBounds",
 
  316     "ctuOneDefinitionRuleViolation",
 
  318     "duplInheritedMember",
 
  320     "exceptThrowInDestructor",
 
  321     "funcArgNamesDifferent",
 
  326     "mismatchAllocDealloc",
 
  329     "noExplicitConstructor",
 
  331     "nullPointerArithmetic",
 
  332     "nullPointerArithmeticRedundantCheck",
 
  333     "nullPointerDefaultArg",
 
  334     "nullPointerRedundantCheck",
 
  336     "overlappingWriteFunction",
 
  337     "overlappingWriteUnion",
 
  338     "pointerOutOfBounds",
 
  339     "pointerOutOfBoundsCond",
 
  340     "preprocessorErrorDirective",
 
  341     "redundantAssignment",
 
  342     "redundantInitialization",
 
  343     "returnDanglingLifetime",
 
  348     "sizeofFunctionCall",
 
  349     "throwInNoexceptFunction",
 
  354     "unsignedLessThanZero",
 
  356     "unusedStructMember",
 
  359     "useInitializationList",
 
  361     "virtualCallInConstructor",
 
  367     "IOWithoutPositioning",
 
  369     "autovarInvalidDeallocation",
 
  376     "floatConversionOverflow",
 
  377     "invalidFunctionArg",
 
  378     "invalidLengthModifierError",
 
  380     "invalidScanfFormatWidth",
 
  382     "leakReturnValNotUsed",
 
  383     "leakUnsafeArgAlloc",
 
  386     "mismatchAllocDealloc",
 
  389     "nullPointerArithmetic",
 
  390     "nullPointerArithmeticRedundantCheck",
 
  391     "nullPointerDefaultArg",
 
  392     "nullPointerRedundantCheck",
 
  393     "preprocessorErrorDirective",
 
  396     "stringLiteralWrite",
 
  397     "uninitStructMember",
 
  400     "unknownEvaluationOrder",
 
  402     "wrongPrintfScanfArgNum",
 
  403     "wrongPrintfScanfParameterPositionError" 
  407     "IOWithoutPositioning",
 
  410     "containerOutOfBounds",
 
  411     "ctuOneDefinitionRuleViolation",
 
  414     "danglingTempReference",
 
  415     "danglingTemporaryLifetime",
 
  420     "exceptThrowInDestructor",
 
  424     "mismatchAllocDealloc",
 
  428     "returnDanglingLifetime",
 
  431     "virtualCallInConstructor",
 
  439     "autovarInvalidDeallocation",
 
  440     "bufferAccessOutOfBounds",
 
  442     "compareValueOutOfTypeRangeError",
 
  443     "constParameterPointer",
 
  445     "danglingTemporaryLifetime",
 
  447     "funcArgNamesDifferent",
 
  448     "incompatibleFileOpen",
 
  449     "invalidFunctionArg",
 
  450     "knownConditionTrueFalse",
 
  451     "leakNoVarFunctionCall",
 
  452     "leakReturnValNotUsed",
 
  456     "overlappingWriteFunction",
 
  457     "overlappingWriteUnion",
 
  458     "pointerOutOfBounds",
 
  459     "preprocessorErrorDirective",
 
  460     "redundantAssignInSwitch",
 
  461     "redundantAssignment",
 
  462     "redundantCondition",
 
  464     "returnDanglingLifetime",
 
  467     "sizeofwithsilentarraypointer",
 
  470     "unknownEvaluationOrder",
 
  483     "autovarInvalidDeallocation",
 
  484     "bufferAccessOutOfBounds",
 
  486     "compareValueOutOfTypeRangeError",
 
  487     "constParameterPointer",
 
  489     "danglingTemporaryLifetime",
 
  491     "funcArgNamesDifferent",
 
  492     "incompatibleFileOpen",
 
  493     "invalidFunctionArg",
 
  494     "knownConditionTrueFalse",
 
  495     "leakNoVarFunctionCall",
 
  496     "leakReturnValNotUsed",
 
  500     "overlappingWriteFunction",
 
  501     "overlappingWriteUnion",
 
  502     "pointerOutOfBounds",
 
  503     "preprocessorErrorDirective",
 
  504     "redundantAssignInSwitch",
 
  505     "redundantAssignment",
 
  506     "redundantCondition",
 
  508     "returnDanglingLifetime",
 
  511     "sizeofwithsilentarraypointer",
 
  514     "unknownEvaluationOrder",
 
  529     "ctuOneDefinitionRuleViolation",
 
  531     "duplInheritedMember",
 
  533     "exceptThrowInDestructor",
 
  534     "funcArgNamesDifferent",
 
  538     "noExplicitConstructor",
 
  539     "overlappingWriteFunction",
 
  540     "overlappingWriteUnion",
 
  541     "pointerOutOfBounds",
 
  542     "preprocessorErrorDirective",
 
  543     "redundantAssignment",
 
  544     "redundantInitialization",
 
  546     "returnTempReference",
 
  549     "sizeofFunctionCall",
 
  550     "uninitDerivedMemberVar",
 
  551     "uninitDerivedMemberVarPrivate",
 
  553     "uninitMemberVarPrivate",
 
  554     "uninitStructMember",
 
  557     "unknownEvaluationOrder",
 
  560     "unsignedLessThanZero",
 
  562     "unusedStructMember",
 
  565     "virtualCallInConstructor" 
  572     "compareBoolExpressionWithInt",
 
  574     "compareValueOutOfTypeRangeError",
 
  576     "constParameterReference",
 
  577     "ctuOneDefinitionRuleViolation",
 
  579     "identicalConditionAfterEarlyExit",
 
  580     "identicalInnerCondition",
 
  581     "ignoredReturnValue",
 
  582     "invalidFunctionArg",
 
  583     "invalidFunctionArgBool",
 
  584     "invalidFunctionArgStr",
 
  585     "knownConditionTrueFalse",
 
  587     "noExplicitConstructor",
 
  589     "overlappingWriteUnion",
 
  590     "pointerOutOfBounds",
 
  591     "pointerOutOfBoundsCond",
 
  592     "preprocessorErrorDirective",
 
  593     "redundantAssignInSwitch",
 
  594     "redundantAssignment",
 
  596     "redundantInitialization",
 
  602     "unknownEvaluationOrder",
 
  605     "virtualCallInConstructor" 
  627     if (
premiumArgs.find(
"--misra-c-20") != std::string::npos) {
 
  629             return a.name == 
"premiumaddon.json";
 
  633             if (
premiumArgs.find(
"--misra-c-2023") != std::string::npos)
 
  634                 arg = 
"--misra-c-2023-rule-texts";
 
  636                 arg = 
"--misra-c-2012-rule-texts";
 
  638             executeCommand(it->executable, {std::move(arg)}, 
"2>&1", output);
 
  647     std::istringstream istr(data);
 
  649     while (std::getline(istr, line)) {
 
  650         std::string::size_type pos = line.find(
' ');
 
  651         if (pos == std::string::npos)
 
  653         std::string 
id = line.substr(0, pos);
 
  654         std::string text = line.substr(pos + 1);
 
  655         if (
id.empty() || text.empty())
 
  662     if (
id.compare(0, 9, 
"misra-c20") != 0)
 
  671 #if defined(HAS_THREADING_MODEL_FORK) 
  672         ExecutorType::Process;
 
  673 #elif defined(HAS_THREADING_MODEL_THREAD) 
  674         ExecutorType::Thread;
 
static std::string join(const std::string &path1, const std::string &path2)
join 2 paths with '/' separators
 
static bool isFile(const std::string &path)
Checks if given path is a file.
 
static std::string getPathFromFilename(const std::string &filename)
Lookup the path part from a filename (e.g., '/tmp/a.h' -> '/tmp/', 'a.h' -> '')
 
static bool isAbsolute(const std::string &path)
Check if given path is absolute.
 
This is just a container for general settings so that we don't need to pass individual values to func...
 
static std::atomic< bool > mTerminated
terminate checking
 
static std::string loadCppcheckCfg(Settings &settings, Suppressions &suppressions)
 
int performanceValueFlowMaxSubFunctionArgs
max number of sets of arguments to pass to subfuncions in valueflow
 
std::string addEnabled(const std::string &str)
Enable extra checks by id.
 
std::map< std::string, std::string > mMisraRuleTexts
 
std::string getMisraRuleText(const std::string &id, const std::string &text) const
 
bool isEnabled(const ValueFlow::Value *value, bool inconclusiveCheck=false) const
Returns true if given value can be shown.
 
SimpleEnableGroup< Checks > checks
 
std::function< int(std::string, std::vector< std::string >, std::string, std::string &)> ExecuteCmdFn
 
std::unordered_set< std::string > addons
addons, either filename of python/json file or json data
 
void setMisraRuleTexts(const ExecuteCmdFn &executeCommand)
 
bool safety
Safety certified behavior Show checkers report when Cppcheck finishes Make cppcheck checking more str...
 
std::string removeEnabled(const std::string &str)
Disable extra checks by id.
 
std::string buildDir
–cppcheck-build-dir.
 
static std::pair< std::string, std::string > getNameAndVersion(const std::string &productName)
 
std::string cppcheckCfgProductName
cppcheck.cfg: Custom product name
 
std::vector< AddonInfo > addonInfos
the loaded addons infos
 
std::string premiumArgs
Extra arguments for Cppcheck Premium addon.
 
std::set< std::string > summaryReturn
 
void setCheckLevel(CheckLevel level)
 
std::string cppcheckCfgAbout
cppcheck.cfg: About text
 
int performanceValueFlowMaxIfCount
–performance-valueflow-max-if-count=C
 
static ExecutorType defaultExecutor()
 
bool isPremiumEnabled(const char id[]) const
Is checker id enabled by premiumArgs.
 
SimpleEnableGroup< Certainty > certainty
 
std::string applyEnabled(const std::string &str, bool enable)
 
SimpleEnableGroup< Severity > severity
 
static std::string parseEnabled(const std::string &str, std::tuple< SimpleEnableGroup< Severity >, SimpleEnableGroup< Checks >> &groups)
 
bool isEnabled(T flag) const
 
void setEnabled(T flag, bool enabled)
 
std::string addSuppressionLine(const std::string &line)
Don't show the given error.
 
bool defaultArg
Is this value passed as default parameter to the function?
 
const Token * condition
Condition that this value depends on.
 
bool isInconclusive() const
 
@ portability
Portability warning.
 
@ information
Checking information.
 
@ performance
Performance warning.
 
@ error
Programming error.
 
CPPCHECKLIB void loadReturn(const std::string &buildDir, std::set< std::string > &summaryReturn)
 
static const std::set< std::string > autosarCheckers
 
static const std::set< std::string > misrac2012Checkers
 
static const std::set< std::string > misrac2023Checkers
 
static const std::set< std::string > misracpp2023Checkers
 
static const std::set< std::string > misracpp2008Checkers
 
static const std::set< std::string > certCppCheckers
 
static const std::set< std::string > certCCheckers
 
static const char XmlExternalFunctions[]
 
static const char XmlInternalFunctions[]
 
static const char XmlClasses[]
 
static const char XmlRootName[]
 
static const char XmlExternalVariables[]
 
SuppressionList nomsg
suppress message (–suppressions)