From 7820b5dbcc8959b44c7e28e49b08060edc1f4a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 14 Jan 2020 21:17:07 +0100 Subject: [PATCH] Rename 'Verification' to 'Bug hunting' --- cli/cmdlineparser.cpp | 47 +++++++++++++++----------------- cli/cppcheckexecutor.cpp | 10 +++---- cli/cppcheckexecutor.h | 4 +-- lib/cppcheck.cpp | 58 ++++++++++++++++++++-------------------- lib/exprengine.cpp | 22 ++++++++------- lib/settings.cpp | 4 +-- lib/settings.h | 16 +++++------ test/testexprengine.cpp | 3 ++- 8 files changed, 82 insertions(+), 82 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 1ef361533..55c7b0685 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -192,33 +192,30 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) else if (std::strcmp(argv[i], "--safe-functions") == 0) mSettings->safeChecks.externalFunctions = mSettings->safeChecks.internalFunctions = true; - // Experimental: Verify - else if (std::strcmp(argv[i], "--verify") == 0) - mSettings->verification = true; - else if (std::strncmp(argv[i], "--verify-report=", 16) == 0) { - mSettings->verification = true; - mSettings->verificationReport = argv[i] + 16; - } else if (std::strcmp(argv[i], "--debug-verify") == 0) - mSettings->debugVerification = true; - else if (std::strncmp(argv[i], "--verify-diff=", 14) == 0) { - std::ifstream fin(argv[i] + 14); - if (!fin.is_open()) { - printMessage("cppcheck: could not open file " + std::string(argv[i] + 14) + "."); - return false; - } + // Bug hunting + else if (std::strcmp(argv[i], "--bug-hunting") == 0) + mSettings->bugHunting = true; + else if (std::strcmp(argv[i], "--debug-bug-hunting") == 0) + mSettings->bugHunting = mSettings->debugBugHunting = true; + /* + else if (std::strncmp(argv[i], "--check-diff=", 13) == 0) { + std::ifstream fin(argv[i] + 13); + if (!fin.is_open()) { + printMessage("cppcheck: could not open file " + std::string(argv[i] + 13) + "."); + return false; + } - mSettings->verifyDiff = Settings::loadDiffFile(fin); - mSettings->verification = true; - - for (const auto &diff: mSettings->verifyDiff) { - if (!Path::acceptFile(diff.filename)) - continue; - const std::string filename = Path::fromNativeSeparators(diff.filename); - if (std::find(mPathNames.begin(), mPathNames.end(), filename) == mPathNames.end()) - mPathNames.push_back(filename); - } - } + mSettings->checkDiff = Settings::loadDiffFile(fin); + for (const auto &diff: mSettings->bugHuntingDiff) { + if (!Path::acceptFile(diff.filename)) + continue; + const std::string filename = Path::fromNativeSeparators(diff.filename); + if (std::find(mPathNames.begin(), mPathNames.end(), filename) == mPathNames.end()) + mPathNames.push_back(filename); + } + } + */ // Enforce language (--language=, -x) else if (std::strncmp(argv[i], "--language=", 11) == 0 || std::strcmp(argv[i], "-x") == 0) { std::string str; diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index cf344da8b..e88965493 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -79,14 +79,14 @@ /*static*/ FILE* CppCheckExecutor::mExceptionOutput = stdout; CppCheckExecutor::CppCheckExecutor() - : mSettings(nullptr), mLatestProgressOutputTime(0), mErrorOutput(nullptr), mVerificationOutput(nullptr), mShowAllErrors(false) + : mSettings(nullptr), mLatestProgressOutputTime(0), mErrorOutput(nullptr), mBugHuntingReport(nullptr), mShowAllErrors(false) { } CppCheckExecutor::~CppCheckExecutor() { delete mErrorOutput; - delete mVerificationOutput; + delete mBugHuntingReport; } bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* const argv[]) @@ -1095,9 +1095,9 @@ void CppCheckExecutor::reportVerification(const std::string &str) { if (!mSettings || str.empty()) return; - if (!mVerificationOutput) - mVerificationOutput = new std::ofstream(mSettings->verificationReport); - (*mVerificationOutput) << str << std::endl; + if (!mBugHuntingReport) + mBugHuntingReport = new std::ofstream(mSettings->bugHuntingReport); + (*mBugHuntingReport) << str << std::endl; } void CppCheckExecutor::setExceptionOutput(FILE* exceptionOutput) diff --git a/cli/cppcheckexecutor.h b/cli/cppcheckexecutor.h index 3d5746a3b..04e5ad7f4 100644 --- a/cli/cppcheckexecutor.h +++ b/cli/cppcheckexecutor.h @@ -190,9 +190,9 @@ private: std::ofstream *mErrorOutput; /** - * Verification report + * Bug hunting report */ - std::ostream *mVerificationOutput; + std::ostream *mBugHuntingReport; /** * Has --errorlist been given? diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 1484c0b73..1b4b895ba 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -301,7 +301,7 @@ unsigned int CppCheck::check(const std::string &path) tokenizer.printDebugOutput(1); #ifdef USE_Z3 - if (mSettings.verification) + if (mSettings.bugHunting) ExprEngine::runChecks(this, &tokenizer, &mSettings); #endif return 0; @@ -838,39 +838,39 @@ void CppCheck::checkRawTokens(const Tokenizer &tokenizer) void CppCheck::checkNormalTokens(const Tokenizer &tokenizer) { - // call all "runChecks" in all registered Check classes - for (Check *check : Check::instances()) { - if (Settings::terminated()) - return; - - if (Tokenizer::isMaxTime()) - return; - - Timer timerRunChecks(check->name() + "::runChecks", mSettings.showtime, &s_timerResults); - check->runChecks(&tokenizer, &mSettings, this); - } - - // Verification using ExprEngine.. - if (mSettings.verification) + if (mSettings.bugHunting) ExprEngine::runChecks(this, &tokenizer, &mSettings); + else { + // call all "runChecks" in all registered Check classes + for (Check *check : Check::instances()) { + if (Settings::terminated()) + return; - // Analyse the tokens.. + if (Tokenizer::isMaxTime()) + return; - CTU::FileInfo *fi1 = CTU::getFileInfo(&tokenizer); - if (fi1) { - mFileInfo.push_back(fi1); - mAnalyzerInformation.setFileInfo("ctu", fi1->toString()); - } - - for (const Check *check : Check::instances()) { - Check::FileInfo *fi = check->getFileInfo(&tokenizer, &mSettings); - if (fi != nullptr) { - mFileInfo.push_back(fi); - mAnalyzerInformation.setFileInfo(check->name(), fi->toString()); + Timer timerRunChecks(check->name() + "::runChecks", mSettings.showtime, &s_timerResults); + check->runChecks(&tokenizer, &mSettings, this); } - } - executeRules("normal", tokenizer); + // Analyse the tokens.. + + CTU::FileInfo *fi1 = CTU::getFileInfo(&tokenizer); + if (fi1) { + mFileInfo.push_back(fi1); + mAnalyzerInformation.setFileInfo("ctu", fi1->toString()); + } + + for (const Check *check : Check::instances()) { + Check::FileInfo *fi = check->getFileInfo(&tokenizer, &mSettings); + if (fi != nullptr) { + mFileInfo.push_back(fi); + mAnalyzerInformation.setFileInfo(check->name(), fi->toString()); + } + } + + executeRules("normal", tokenizer); + } } //--------------------------------------------------------------------------- diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index c75912daf..c8342ca94 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -1719,20 +1719,20 @@ void ExprEngine::executeFunction(const Scope *functionScope, const Tokenizer *to // TODO.. what about functions in headers? return; - if (!settings->verifyDiff.empty()) { + if (!settings->checkDiff.empty()) { const std::string filename = tokenizer->list.getFiles().at(functionScope->bodyStart->fileIndex()); - bool verify = false; - for (const auto &diff: settings->verifyDiff) { + bool check = false; + for (const auto &diff: settings->checkDiff) { if (diff.filename != filename) continue; if (diff.fromLine > functionScope->bodyEnd->linenr()) continue; if (diff.toLine < functionScope->bodyStart->linenr()) continue; - verify = true; + check = true; break; } - if (!verify) + if (!check) return; } @@ -1757,19 +1757,21 @@ void ExprEngine::executeFunction(const Scope *functionScope, const Tokenizer *to } } - if (settings->debugVerification && (settings->verbose || callbacks.empty() || !trackExecution.isAllOk())) { - if (!settings->verificationReport.empty()) + const bool bugHuntingReport = !settings->bugHuntingReport.empty(); + + if (settings->debugBugHunting && (settings->verbose || callbacks.empty() || !trackExecution.isAllOk())) { + if (bugHuntingReport) report << "[debug]" << std::endl; trackExecution.print(report); if (!callbacks.empty()) { - if (!settings->verificationReport.empty()) + if (bugHuntingReport) report << "[details]" << std::endl; trackExecution.report(report, functionScope); } } // Write a verification report - if (!settings->verificationReport.empty()) { + if (bugHuntingReport) { report << "[function-report] " << Path::stripDirectoryPart(tokenizer->list.getFiles().at(functionScope->bodyStart->fileIndex())) << ":" << functionScope->bodyStart->linenr() << ":" @@ -2044,7 +2046,7 @@ void ExprEngine::runChecks(ErrorLogger *errorLogger, const Tokenizer *tokenizer, std::ostringstream report; ExprEngine::executeAllFunctions(tokenizer, settings, callbacks, report); - if (settings->verificationReport.empty()) + if (settings->bugHuntingReport.empty()) std::cout << report.str(); else if (errorLogger) errorLogger->reportVerification(report.str()); diff --git a/lib/settings.cpp b/lib/settings.cpp index b74566e3c..be45d473e 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -46,8 +46,8 @@ Settings::Settings() experimental(false), force(false), inconclusive(false), - verification(false), - debugVerification(false), + bugHunting(false), + debugBugHunting(false), inlineSuppressions(false), jobs(1), jointSuppressionReport(false), diff --git a/lib/settings.h b/lib/settings.h index c60a2886a..59b183064 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -194,22 +194,22 @@ public: SafeChecks safeChecks; - /** @brief Enable verification analysis */ - bool verification; + /** @brief Bug hunting */ + bool bugHunting; - /** @brief Verification report filename */ - std::string verificationReport; + /** @brief Debug bug hunting */ + bool debugBugHunting; - /** @brief Generate verification debug output */ - bool debugVerification; + /** Filename for bug hunting report */ + std::string bugHuntingReport; - /** @brief Verify diff */ + /** @brief Check diff */ struct Diff { std::string filename; int fromLine; int toLine; }; - std::vector verifyDiff; + std::vector checkDiff; /** @brief check unknown function return values */ std::set checkUnknownFunctionReturn; diff --git a/test/testexprengine.cpp b/test/testexprengine.cpp index d5cedf168..3487ebfbe 100644 --- a/test/testexprengine.cpp +++ b/test/testexprengine.cpp @@ -137,7 +137,8 @@ private: std::string trackExecution(const char code[]) { Settings settings; - settings.debugVerification = true; + settings.bugHunting = true; + settings.debugBugHunting = true; settings.platform(cppcheck::Platform::Unix64); settings.library.smartPointers.insert("std::shared_ptr"); Tokenizer tokenizer(&settings, this);