diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 6ba1ace54..b976742bc 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -155,6 +155,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) else if (std::strcmp(argv[i], "--dump") == 0) mSettings->dump = true; + // max ctu depth + else if (std::strncmp(argv[i], "--max-ctu-depth=", 16) == 0) + mSettings->maxCtuDepth = std::atoi(argv[i] + 16); + // (Experimental) exception handling inside cppcheck client else if (std::strcmp(argv[i], "--exception-handling") == 0) mSettings->exceptionHandling = true; @@ -1013,6 +1017,9 @@ void CmdLineParser::printHelp() " distributed with Cppcheck is loaded automatically.\n" " For more information about library files, read the\n" " manual.\n" + " --max-ctu-depth=N Max depth in whole program analysis. The default value\n" + " is 2. A larger value will mean more errors can be found\n" + " but also means the analysis will be slower.\n" " --output-file= Write results to file, rather than standard error.\n" " --project= Run Cppcheck on project. The can be a Visual\n" " Studio Solution (*.sln), Visual Studio Project\n" diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 1ac478bab..c3a7a1999 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1036,6 +1036,8 @@ void CppCheck::getErrorMessages() bool CppCheck::analyseWholeProgram() { bool errors = false; + // Init CTU + CTU::maxCtuDepth = mSettings.maxCtuDepth; // Analyse the tokens CTU::FileInfo ctu; for (const Check::FileInfo *fi : mFileInfo) { @@ -1100,6 +1102,9 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::mapanalyseWholeProgram(&ctuFileInfo, fileInfoList, mSettings, *this); diff --git a/lib/ctu.cpp b/lib/ctu.cpp index 75d897073..841d9914f 100644 --- a/lib/ctu.cpp +++ b/lib/ctu.cpp @@ -38,6 +38,7 @@ static const char ATTR_MY_ID[] = "my-id"; static const char ATTR_MY_ARGNR[] = "my-argnr"; static const char ATTR_MY_ARGNAME[] = "my-argname"; +int CTU::maxCtuDepth = 2; std::string CTU::getFunctionId(const Tokenizer *tokenizer, const Function *function) { @@ -426,7 +427,7 @@ static bool findPath(const std::string &callId, int index, bool warning) { - if (index >= 10) + if (index >= CTU::maxCtuDepth || index >= 10) return false; const std::map>::const_iterator it = callsMap.find(callId); diff --git a/lib/ctu.h b/lib/ctu.h index 30f315066..0cd253210 100644 --- a/lib/ctu.h +++ b/lib/ctu.h @@ -117,6 +117,8 @@ namespace CTU { bool warning) const; }; + extern int maxCtuDepth; + CPPCHECKLIB std::string toString(const std::list &unsafeUsage); CPPCHECKLIB std::string getFunctionId(const Tokenizer *tokenizer, const Function *function); diff --git a/lib/settings.cpp b/lib/settings.cpp index dd36fc308..ea5a0a262 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -32,6 +32,7 @@ Settings::Settings() exceptionHandling(false), inconclusive(false), jointSuppressionReport(false), + maxCtuDepth(2), experimental(false), quiet(false), inlineSuppressions(false), diff --git a/lib/settings.h b/lib/settings.h index 4b43e8178..45d696628 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -85,6 +85,9 @@ public: /** @brief Is --debug-template given? */ bool debugtemplate; + /** @brief --max-ctu-depth */ + int maxCtuDepth; + /** @brief Is --dump given? */ bool dump; std::string dumpFile; diff --git a/man/cppcheck.1.xml b/man/cppcheck.1.xml index 77752009c..cde1f8256 100644 --- a/man/cppcheck.1.xml +++ b/man/cppcheck.1.xml @@ -165,6 +165,9 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ + + + @@ -457,6 +460,14 @@ There are false positives with this option. Each result must be carefully invest the one that is effective. + + + + + + Maximum depth in whole program analysis. Default is 2. + +