Rename 'Verification' to 'Bug hunting'

This commit is contained in:
Daniel Marjamäki 2020-01-14 21:17:07 +01:00
parent 434b506e58
commit 7820b5dbcc
8 changed files with 82 additions and 82 deletions

View File

@ -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;

View File

@ -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)

View File

@ -190,9 +190,9 @@ private:
std::ofstream *mErrorOutput;
/**
* Verification report
* Bug hunting report
*/
std::ostream *mVerificationOutput;
std::ostream *mBugHuntingReport;
/**
* Has --errorlist been given?

View File

@ -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);
}
}
//---------------------------------------------------------------------------

View File

@ -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());

View File

@ -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),

View File

@ -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;

View File

@ -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);