Improve MAXTIME handling

This commit is contained in:
Daniel Marjamäki 2016-02-11 16:10:52 +01:00
parent 1f27c4b76b
commit cef6b35bb8
4 changed files with 30 additions and 7 deletions

View File

@ -1127,6 +1127,13 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
for (unsigned int i = 1; i <= _tokenizer->varIdCount(); i++) {
const Variable * const var = symbolDatabase->getVariableFromVarId(i);
if (var && var->isArray() && var->dimension(0) > 0) {
_errorLogger->reportProgress(_tokenizer->list.getSourceFilePath(),
"Check (BufferOverrun::checkGlobalAndLocalVariable 1)",
var->nameToken()->progressValue());
if (_tokenizer->isMaxTime())
return;
const Token *tok = var->nameToken();
do {
if (tok->str() == "{") {
@ -1169,9 +1176,12 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
int nextTok = 0;
_errorLogger->reportProgress(_tokenizer->list.getSourceFilePath(),
"Check (BufferOverrun::checkGlobalAndLocalVariable)",
"Check (BufferOverrun::checkGlobalAndLocalVariable 2)",
tok->progressValue());
if (_tokenizer->isMaxTime())
return;
if (_tokenizer->isCPP() && Token::Match(tok, "[*;{}] %var% = new %type% [ %num% ]")) {
size = MathLib::toLongNumber(tok->strAt(6));
type = tok->strAt(4);
@ -1412,6 +1422,8 @@ void CheckBufferOverrun::checkStructVariable()
void CheckBufferOverrun::bufferOverrun()
{
checkGlobalAndLocalVariable();
if (_tokenizer->isMaxTime())
return;
checkStructVariable();
checkBufferAllocatedWithStrlen();
checkStringArgument();

View File

@ -357,6 +357,9 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
if (_settings.terminated())
return;
if (tokenizer.isMaxTime())
return;
Timer timerRunChecks((*it)->name() + "::runChecks", _settings.showtime, &S_timerResults);
(*it)->runChecks(&tokenizer, &_settings, this);
}
@ -382,6 +385,9 @@ void CppCheck::checkSimplifiedTokens(const Tokenizer &tokenizer)
if (_settings.terminated())
return;
if (tokenizer.isMaxTime())
return;
Timer timerSimpleChecks((*it)->name() + "::runSimplifiedChecks", _settings.showtime, &S_timerResults);
(*it)->runSimplifiedChecks(&tokenizer, &_settings, this);
timerSimpleChecks.Stop();

View File

@ -545,10 +545,8 @@ void Tokenizer::simplifyTypedef()
if (_settings->terminated())
return;
#ifdef MAXTIME
if (std::time(0) > maxtime)
if (isMaxTime())
return;
#endif
if (goback) {
//jump back once, see the comment at the end of the function
@ -6421,10 +6419,8 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
if (_errorLogger && !list.getFiles().empty())
_errorLogger->reportProgress(list.getFiles()[0], "Tokenize (simplifyKnownVariables)", tok3->progressValue());
#ifdef MAXTIME
if (std::time(0) > maxtime)
if (isMaxTime())
return false;
#endif
bool ret = false;

View File

@ -811,6 +811,14 @@ public:
*/
static const Token * startOfExecutableScope(const Token * tok);
bool isMaxTime() const {
#ifdef MAXTIME
return (std::time(0) > maxtime);
#else
return false;
#endif
}
private:
/** Disable copy constructor, no implementation */
Tokenizer(const Tokenizer &);
@ -852,6 +860,7 @@ private:
* TimerResults
*/
TimerResults *m_timerResults;
#ifdef MAXTIME
/** Tokenizer maxtime */
std::time_t maxtime;