Rename 'Verification' to 'Bug hunting'
This commit is contained in:
parent
434b506e58
commit
7820b5dbcc
|
@ -192,25 +192,22 @@ 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);
|
||||
// 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] + 14) + ".");
|
||||
printMessage("cppcheck: could not open file " + std::string(argv[i] + 13) + ".");
|
||||
return false;
|
||||
}
|
||||
|
||||
mSettings->verifyDiff = Settings::loadDiffFile(fin);
|
||||
mSettings->verification = true;
|
||||
mSettings->checkDiff = Settings::loadDiffFile(fin);
|
||||
|
||||
for (const auto &diff: mSettings->verifyDiff) {
|
||||
for (const auto &diff: mSettings->bugHuntingDiff) {
|
||||
if (!Path::acceptFile(diff.filename))
|
||||
continue;
|
||||
const std::string filename = Path::fromNativeSeparators(diff.filename);
|
||||
|
@ -218,7 +215,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
|||
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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -190,9 +190,9 @@ private:
|
|||
std::ofstream *mErrorOutput;
|
||||
|
||||
/**
|
||||
* Verification report
|
||||
* Bug hunting report
|
||||
*/
|
||||
std::ostream *mVerificationOutput;
|
||||
std::ostream *mBugHuntingReport;
|
||||
|
||||
/**
|
||||
* Has --errorlist been given?
|
||||
|
|
|
@ -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,6 +838,9 @@ void CppCheck::checkRawTokens(const Tokenizer &tokenizer)
|
|||
|
||||
void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
|
||||
{
|
||||
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())
|
||||
|
@ -850,10 +853,6 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
|
|||
check->runChecks(&tokenizer, &mSettings, this);
|
||||
}
|
||||
|
||||
// Verification using ExprEngine..
|
||||
if (mSettings.verification)
|
||||
ExprEngine::runChecks(this, &tokenizer, &mSettings);
|
||||
|
||||
// Analyse the tokens..
|
||||
|
||||
CTU::FileInfo *fi1 = CTU::getFileInfo(&tokenizer);
|
||||
|
@ -872,6 +871,7 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
|
|||
|
||||
executeRules("normal", tokenizer);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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<Diff> verifyDiff;
|
||||
std::vector<Diff> checkDiff;
|
||||
|
||||
/** @brief check unknown function return values */
|
||||
std::set<std::string> checkUnknownFunctionReturn;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue