Rename 'Verification' to 'Bug hunting'
This commit is contained in:
parent
434b506e58
commit
7820b5dbcc
|
@ -192,33 +192,30 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
else if (std::strcmp(argv[i], "--safe-functions") == 0)
|
else if (std::strcmp(argv[i], "--safe-functions") == 0)
|
||||||
mSettings->safeChecks.externalFunctions = mSettings->safeChecks.internalFunctions = true;
|
mSettings->safeChecks.externalFunctions = mSettings->safeChecks.internalFunctions = true;
|
||||||
|
|
||||||
// Experimental: Verify
|
// Bug hunting
|
||||||
else if (std::strcmp(argv[i], "--verify") == 0)
|
else if (std::strcmp(argv[i], "--bug-hunting") == 0)
|
||||||
mSettings->verification = true;
|
mSettings->bugHunting = true;
|
||||||
else if (std::strncmp(argv[i], "--verify-report=", 16) == 0) {
|
else if (std::strcmp(argv[i], "--debug-bug-hunting") == 0)
|
||||||
mSettings->verification = true;
|
mSettings->bugHunting = mSettings->debugBugHunting = true;
|
||||||
mSettings->verificationReport = argv[i] + 16;
|
/*
|
||||||
} else if (std::strcmp(argv[i], "--debug-verify") == 0)
|
else if (std::strncmp(argv[i], "--check-diff=", 13) == 0) {
|
||||||
mSettings->debugVerification = true;
|
std::ifstream fin(argv[i] + 13);
|
||||||
else if (std::strncmp(argv[i], "--verify-diff=", 14) == 0) {
|
if (!fin.is_open()) {
|
||||||
std::ifstream fin(argv[i] + 14);
|
printMessage("cppcheck: could not open file " + std::string(argv[i] + 13) + ".");
|
||||||
if (!fin.is_open()) {
|
return false;
|
||||||
printMessage("cppcheck: could not open file " + std::string(argv[i] + 14) + ".");
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
mSettings->verifyDiff = Settings::loadDiffFile(fin);
|
mSettings->checkDiff = 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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)
|
// Enforce language (--language=, -x)
|
||||||
else if (std::strncmp(argv[i], "--language=", 11) == 0 || std::strcmp(argv[i], "-x") == 0) {
|
else if (std::strncmp(argv[i], "--language=", 11) == 0 || std::strcmp(argv[i], "-x") == 0) {
|
||||||
std::string str;
|
std::string str;
|
||||||
|
|
|
@ -79,14 +79,14 @@
|
||||||
/*static*/ FILE* CppCheckExecutor::mExceptionOutput = stdout;
|
/*static*/ FILE* CppCheckExecutor::mExceptionOutput = stdout;
|
||||||
|
|
||||||
CppCheckExecutor::CppCheckExecutor()
|
CppCheckExecutor::CppCheckExecutor()
|
||||||
: mSettings(nullptr), mLatestProgressOutputTime(0), mErrorOutput(nullptr), mVerificationOutput(nullptr), mShowAllErrors(false)
|
: mSettings(nullptr), mLatestProgressOutputTime(0), mErrorOutput(nullptr), mBugHuntingReport(nullptr), mShowAllErrors(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CppCheckExecutor::~CppCheckExecutor()
|
CppCheckExecutor::~CppCheckExecutor()
|
||||||
{
|
{
|
||||||
delete mErrorOutput;
|
delete mErrorOutput;
|
||||||
delete mVerificationOutput;
|
delete mBugHuntingReport;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* const argv[])
|
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())
|
if (!mSettings || str.empty())
|
||||||
return;
|
return;
|
||||||
if (!mVerificationOutput)
|
if (!mBugHuntingReport)
|
||||||
mVerificationOutput = new std::ofstream(mSettings->verificationReport);
|
mBugHuntingReport = new std::ofstream(mSettings->bugHuntingReport);
|
||||||
(*mVerificationOutput) << str << std::endl;
|
(*mBugHuntingReport) << str << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCheckExecutor::setExceptionOutput(FILE* exceptionOutput)
|
void CppCheckExecutor::setExceptionOutput(FILE* exceptionOutput)
|
||||||
|
|
|
@ -190,9 +190,9 @@ private:
|
||||||
std::ofstream *mErrorOutput;
|
std::ofstream *mErrorOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verification report
|
* Bug hunting report
|
||||||
*/
|
*/
|
||||||
std::ostream *mVerificationOutput;
|
std::ostream *mBugHuntingReport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Has --errorlist been given?
|
* Has --errorlist been given?
|
||||||
|
|
|
@ -301,7 +301,7 @@ unsigned int CppCheck::check(const std::string &path)
|
||||||
tokenizer.printDebugOutput(1);
|
tokenizer.printDebugOutput(1);
|
||||||
|
|
||||||
#ifdef USE_Z3
|
#ifdef USE_Z3
|
||||||
if (mSettings.verification)
|
if (mSettings.bugHunting)
|
||||||
ExprEngine::runChecks(this, &tokenizer, &mSettings);
|
ExprEngine::runChecks(this, &tokenizer, &mSettings);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -838,39 +838,39 @@ void CppCheck::checkRawTokens(const Tokenizer &tokenizer)
|
||||||
|
|
||||||
void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
|
void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
|
||||||
{
|
{
|
||||||
// call all "runChecks" in all registered Check classes
|
if (mSettings.bugHunting)
|
||||||
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)
|
|
||||||
ExprEngine::runChecks(this, &tokenizer, &mSettings);
|
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);
|
Timer timerRunChecks(check->name() + "::runChecks", mSettings.showtime, &s_timerResults);
|
||||||
if (fi1) {
|
check->runChecks(&tokenizer, &mSettings, this);
|
||||||
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);
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -1719,20 +1719,20 @@ void ExprEngine::executeFunction(const Scope *functionScope, const Tokenizer *to
|
||||||
// TODO.. what about functions in headers?
|
// TODO.. what about functions in headers?
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!settings->verifyDiff.empty()) {
|
if (!settings->checkDiff.empty()) {
|
||||||
const std::string filename = tokenizer->list.getFiles().at(functionScope->bodyStart->fileIndex());
|
const std::string filename = tokenizer->list.getFiles().at(functionScope->bodyStart->fileIndex());
|
||||||
bool verify = false;
|
bool check = false;
|
||||||
for (const auto &diff: settings->verifyDiff) {
|
for (const auto &diff: settings->checkDiff) {
|
||||||
if (diff.filename != filename)
|
if (diff.filename != filename)
|
||||||
continue;
|
continue;
|
||||||
if (diff.fromLine > functionScope->bodyEnd->linenr())
|
if (diff.fromLine > functionScope->bodyEnd->linenr())
|
||||||
continue;
|
continue;
|
||||||
if (diff.toLine < functionScope->bodyStart->linenr())
|
if (diff.toLine < functionScope->bodyStart->linenr())
|
||||||
continue;
|
continue;
|
||||||
verify = true;
|
check = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!verify)
|
if (!check)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1757,19 +1757,21 @@ void ExprEngine::executeFunction(const Scope *functionScope, const Tokenizer *to
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings->debugVerification && (settings->verbose || callbacks.empty() || !trackExecution.isAllOk())) {
|
const bool bugHuntingReport = !settings->bugHuntingReport.empty();
|
||||||
if (!settings->verificationReport.empty())
|
|
||||||
|
if (settings->debugBugHunting && (settings->verbose || callbacks.empty() || !trackExecution.isAllOk())) {
|
||||||
|
if (bugHuntingReport)
|
||||||
report << "[debug]" << std::endl;
|
report << "[debug]" << std::endl;
|
||||||
trackExecution.print(report);
|
trackExecution.print(report);
|
||||||
if (!callbacks.empty()) {
|
if (!callbacks.empty()) {
|
||||||
if (!settings->verificationReport.empty())
|
if (bugHuntingReport)
|
||||||
report << "[details]" << std::endl;
|
report << "[details]" << std::endl;
|
||||||
trackExecution.report(report, functionScope);
|
trackExecution.report(report, functionScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write a verification report
|
// Write a verification report
|
||||||
if (!settings->verificationReport.empty()) {
|
if (bugHuntingReport) {
|
||||||
report << "[function-report] "
|
report << "[function-report] "
|
||||||
<< Path::stripDirectoryPart(tokenizer->list.getFiles().at(functionScope->bodyStart->fileIndex())) << ":"
|
<< Path::stripDirectoryPart(tokenizer->list.getFiles().at(functionScope->bodyStart->fileIndex())) << ":"
|
||||||
<< functionScope->bodyStart->linenr() << ":"
|
<< functionScope->bodyStart->linenr() << ":"
|
||||||
|
@ -2044,7 +2046,7 @@ void ExprEngine::runChecks(ErrorLogger *errorLogger, const Tokenizer *tokenizer,
|
||||||
|
|
||||||
std::ostringstream report;
|
std::ostringstream report;
|
||||||
ExprEngine::executeAllFunctions(tokenizer, settings, callbacks, report);
|
ExprEngine::executeAllFunctions(tokenizer, settings, callbacks, report);
|
||||||
if (settings->verificationReport.empty())
|
if (settings->bugHuntingReport.empty())
|
||||||
std::cout << report.str();
|
std::cout << report.str();
|
||||||
else if (errorLogger)
|
else if (errorLogger)
|
||||||
errorLogger->reportVerification(report.str());
|
errorLogger->reportVerification(report.str());
|
||||||
|
|
|
@ -46,8 +46,8 @@ Settings::Settings()
|
||||||
experimental(false),
|
experimental(false),
|
||||||
force(false),
|
force(false),
|
||||||
inconclusive(false),
|
inconclusive(false),
|
||||||
verification(false),
|
bugHunting(false),
|
||||||
debugVerification(false),
|
debugBugHunting(false),
|
||||||
inlineSuppressions(false),
|
inlineSuppressions(false),
|
||||||
jobs(1),
|
jobs(1),
|
||||||
jointSuppressionReport(false),
|
jointSuppressionReport(false),
|
||||||
|
|
|
@ -194,22 +194,22 @@ public:
|
||||||
|
|
||||||
SafeChecks safeChecks;
|
SafeChecks safeChecks;
|
||||||
|
|
||||||
/** @brief Enable verification analysis */
|
/** @brief Bug hunting */
|
||||||
bool verification;
|
bool bugHunting;
|
||||||
|
|
||||||
/** @brief Verification report filename */
|
/** @brief Debug bug hunting */
|
||||||
std::string verificationReport;
|
bool debugBugHunting;
|
||||||
|
|
||||||
/** @brief Generate verification debug output */
|
/** Filename for bug hunting report */
|
||||||
bool debugVerification;
|
std::string bugHuntingReport;
|
||||||
|
|
||||||
/** @brief Verify diff */
|
/** @brief Check diff */
|
||||||
struct Diff {
|
struct Diff {
|
||||||
std::string filename;
|
std::string filename;
|
||||||
int fromLine;
|
int fromLine;
|
||||||
int toLine;
|
int toLine;
|
||||||
};
|
};
|
||||||
std::vector<Diff> verifyDiff;
|
std::vector<Diff> checkDiff;
|
||||||
|
|
||||||
/** @brief check unknown function return values */
|
/** @brief check unknown function return values */
|
||||||
std::set<std::string> checkUnknownFunctionReturn;
|
std::set<std::string> checkUnknownFunctionReturn;
|
||||||
|
|
|
@ -137,7 +137,8 @@ private:
|
||||||
|
|
||||||
std::string trackExecution(const char code[]) {
|
std::string trackExecution(const char code[]) {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.debugVerification = true;
|
settings.bugHunting = true;
|
||||||
|
settings.debugBugHunting = true;
|
||||||
settings.platform(cppcheck::Platform::Unix64);
|
settings.platform(cppcheck::Platform::Unix64);
|
||||||
settings.library.smartPointers.insert("std::shared_ptr");
|
settings.library.smartPointers.insert("std::shared_ptr");
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
|
|
Loading…
Reference in New Issue