Bug hunting; option to set function analysis max time
This commit is contained in:
parent
87468dff3b
commit
1b0ca0811f
|
@ -219,6 +219,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
else if (std::strcmp(argv[i], "--bug-hunting") == 0)
|
else if (std::strcmp(argv[i], "--bug-hunting") == 0)
|
||||||
mSettings->bugHunting = true;
|
mSettings->bugHunting = true;
|
||||||
|
|
||||||
|
// TODO: Rename or move this parameter?
|
||||||
|
else if (std::strncmp(argv[i], "--bug-hunting-check-function-max-time=", 38) == 0)
|
||||||
|
mSettings->bugHuntingCheckFunctionMaxTime = std::atoi(argv[i] + 38);
|
||||||
|
|
||||||
// Check configuration
|
// Check configuration
|
||||||
else if (std::strcmp(argv[i], "--check-config") == 0)
|
else if (std::strcmp(argv[i], "--check-config") == 0)
|
||||||
mSettings->checkConfiguration = true;
|
mSettings->checkConfiguration = true;
|
||||||
|
|
|
@ -2428,6 +2428,10 @@ static std::string execute(const Token *start, const Token *end, Data &data)
|
||||||
};
|
};
|
||||||
Recursion updateRecursion(&data.recursion, data.recursion);
|
Recursion updateRecursion(&data.recursion, data.recursion);
|
||||||
|
|
||||||
|
const std::time_t stopTime = (data.settings->bugHuntingCheckFunctionMaxTime > 0) ?
|
||||||
|
(data.startTime + data.settings->bugHuntingCheckFunctionMaxTime) :
|
||||||
|
~0ULL;
|
||||||
|
|
||||||
for (const Token *tok = start; tok != end; tok = tok->next()) {
|
for (const Token *tok = start; tok != end; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "[;{}]")) {
|
if (Token::Match(tok, "[;{}]")) {
|
||||||
data.trackProgramState(tok);
|
data.trackProgramState(tok);
|
||||||
|
@ -2438,6 +2442,8 @@ static std::string execute(const Token *start, const Token *end, Data &data)
|
||||||
if (Token::Match(prev, "[;{}] return|throw"))
|
if (Token::Match(prev, "[;{}] return|throw"))
|
||||||
return data.str();
|
return data.str();
|
||||||
}
|
}
|
||||||
|
if (std::time(nullptr) > stopTime)
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::simpleMatch(tok, "__CPPCHECK_BAILOUT__ ;"))
|
if (Token::simpleMatch(tok, "__CPPCHECK_BAILOUT__ ;"))
|
||||||
|
@ -2850,6 +2856,10 @@ void ExprEngine::executeFunction(const Scope *functionScope, ErrorLogger *errorL
|
||||||
|
|
||||||
data.contractConstraints(function, executeExpression1);
|
data.contractConstraints(function, executeExpression1);
|
||||||
|
|
||||||
|
const std::time_t stopTime = (data.settings->bugHuntingCheckFunctionMaxTime > 0) ?
|
||||||
|
(data.startTime + data.settings->bugHuntingCheckFunctionMaxTime) :
|
||||||
|
~0ULL;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
execute(functionScope->bodyStart, functionScope->bodyEnd, data);
|
execute(functionScope->bodyStart, functionScope->bodyEnd, data);
|
||||||
} catch (const ExprEngineException &e) {
|
} catch (const ExprEngineException &e) {
|
||||||
|
@ -2858,6 +2868,8 @@ void ExprEngine::executeFunction(const Scope *functionScope, ErrorLogger *errorL
|
||||||
trackExecution.setAbortLine(e.tok->linenr());
|
trackExecution.setAbortLine(e.tok->linenr());
|
||||||
auto bailoutValue = std::make_shared<BailoutValue>();
|
auto bailoutValue = std::make_shared<BailoutValue>();
|
||||||
for (const Token *tok = e.tok; tok != functionScope->bodyEnd; tok = tok->next()) {
|
for (const Token *tok = e.tok; tok != functionScope->bodyEnd; tok = tok->next()) {
|
||||||
|
if (std::time(nullptr) >= stopTime)
|
||||||
|
break;
|
||||||
if (Token::Match(tok, "return|throw|while|if|for (")) {
|
if (Token::Match(tok, "return|throw|while|if|for (")) {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -31,6 +31,7 @@ const char Settings::SafeChecks::XmlExternalVariables[] = "external-variables";
|
||||||
Settings::Settings()
|
Settings::Settings()
|
||||||
: mEnabled(0),
|
: mEnabled(0),
|
||||||
bugHunting(false),
|
bugHunting(false),
|
||||||
|
bugHuntingCheckFunctionMaxTime(0),
|
||||||
checkAllConfigurations(true),
|
checkAllConfigurations(true),
|
||||||
checkConfiguration(false),
|
checkConfiguration(false),
|
||||||
checkHeaders(true),
|
checkHeaders(true),
|
||||||
|
|
|
@ -83,6 +83,10 @@ public:
|
||||||
/** @brief Bug hunting */
|
/** @brief Bug hunting */
|
||||||
bool bugHunting;
|
bool bugHunting;
|
||||||
|
|
||||||
|
/** @brief Max time for bug hunting analysis in seconds, after
|
||||||
|
* timeout the analysis will just stop. */
|
||||||
|
int bugHuntingCheckFunctionMaxTime;
|
||||||
|
|
||||||
/** Filename for bug hunting report */
|
/** Filename for bug hunting report */
|
||||||
std::string bugHuntingReport;
|
std::string bugHuntingReport;
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ def get_error_lines(filename):
|
||||||
def check(filename):
|
def check(filename):
|
||||||
cmd = [CPPCHECK_PATH,
|
cmd = [CPPCHECK_PATH,
|
||||||
'--bug-hunting',
|
'--bug-hunting',
|
||||||
|
'--bug-hunting-check-function-max-time=10'
|
||||||
'--platform=unix64',
|
'--platform=unix64',
|
||||||
filename]
|
filename]
|
||||||
if RUN_CLANG:
|
if RUN_CLANG:
|
||||||
|
|
Loading…
Reference in New Issue