From cef6b35bb8d334f8cd42aa03ba81def9f7587847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 11 Feb 2016 16:10:52 +0100 Subject: [PATCH] Improve MAXTIME handling --- lib/checkbufferoverrun.cpp | 14 +++++++++++++- lib/cppcheck.cpp | 6 ++++++ lib/tokenize.cpp | 8 ++------ lib/tokenize.h | 9 +++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 693f920a5..c7abee0cb 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -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(); diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 4a04c72f0..9e79246cc 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -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(); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 8a8d06a07..9686b8b33 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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; diff --git a/lib/tokenize.h b/lib/tokenize.h index 476af34fd..e5e11fcea 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -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;