Skip to content

Commit cef6b35

Browse files
committed
Improve MAXTIME handling
1 parent 1f27c4b commit cef6b35

4 files changed

Lines changed: 30 additions & 7 deletions

File tree

lib/checkbufferoverrun.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,13 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
11271127
for (unsigned int i = 1; i <= _tokenizer->varIdCount(); i++) {
11281128
const Variable * const var = symbolDatabase->getVariableFromVarId(i);
11291129
if (var && var->isArray() && var->dimension(0) > 0) {
1130+
_errorLogger->reportProgress(_tokenizer->list.getSourceFilePath(),
1131+
"Check (BufferOverrun::checkGlobalAndLocalVariable 1)",
1132+
var->nameToken()->progressValue());
1133+
1134+
if (_tokenizer->isMaxTime())
1135+
return;
1136+
11301137
const Token *tok = var->nameToken();
11311138
do {
11321139
if (tok->str() == "{") {
@@ -1169,9 +1176,12 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
11691176
int nextTok = 0;
11701177

11711178
_errorLogger->reportProgress(_tokenizer->list.getSourceFilePath(),
1172-
"Check (BufferOverrun::checkGlobalAndLocalVariable)",
1179+
"Check (BufferOverrun::checkGlobalAndLocalVariable 2)",
11731180
tok->progressValue());
11741181

1182+
if (_tokenizer->isMaxTime())
1183+
return;
1184+
11751185
if (_tokenizer->isCPP() && Token::Match(tok, "[*;{}] %var% = new %type% [ %num% ]")) {
11761186
size = MathLib::toLongNumber(tok->strAt(6));
11771187
type = tok->strAt(4);
@@ -1412,6 +1422,8 @@ void CheckBufferOverrun::checkStructVariable()
14121422
void CheckBufferOverrun::bufferOverrun()
14131423
{
14141424
checkGlobalAndLocalVariable();
1425+
if (_tokenizer->isMaxTime())
1426+
return;
14151427
checkStructVariable();
14161428
checkBufferAllocatedWithStrlen();
14171429
checkStringArgument();

lib/cppcheck.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
357357
if (_settings.terminated())
358358
return;
359359

360+
if (tokenizer.isMaxTime())
361+
return;
362+
360363
Timer timerRunChecks((*it)->name() + "::runChecks", _settings.showtime, &S_timerResults);
361364
(*it)->runChecks(&tokenizer, &_settings, this);
362365
}
@@ -382,6 +385,9 @@ void CppCheck::checkSimplifiedTokens(const Tokenizer &tokenizer)
382385
if (_settings.terminated())
383386
return;
384387

388+
if (tokenizer.isMaxTime())
389+
return;
390+
385391
Timer timerSimpleChecks((*it)->name() + "::runSimplifiedChecks", _settings.showtime, &S_timerResults);
386392
(*it)->runSimplifiedChecks(&tokenizer, &_settings, this);
387393
timerSimpleChecks.Stop();

lib/tokenize.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,8 @@ void Tokenizer::simplifyTypedef()
545545
if (_settings->terminated())
546546
return;
547547

548-
#ifdef MAXTIME
549-
if (std::time(0) > maxtime)
548+
if (isMaxTime())
550549
return;
551-
#endif
552550

553551
if (goback) {
554552
//jump back once, see the comment at the end of the function
@@ -6421,10 +6419,8 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
64216419
if (_errorLogger && !list.getFiles().empty())
64226420
_errorLogger->reportProgress(list.getFiles()[0], "Tokenize (simplifyKnownVariables)", tok3->progressValue());
64236421

6424-
#ifdef MAXTIME
6425-
if (std::time(0) > maxtime)
6422+
if (isMaxTime())
64266423
return false;
6427-
#endif
64286424

64296425
bool ret = false;
64306426

lib/tokenize.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,14 @@ class CPPCHECKLIB Tokenizer {
811811
*/
812812
static const Token * startOfExecutableScope(const Token * tok);
813813

814+
bool isMaxTime() const {
815+
#ifdef MAXTIME
816+
return (std::time(0) > maxtime);
817+
#else
818+
return false;
819+
#endif
820+
}
821+
814822
private:
815823
/** Disable copy constructor, no implementation */
816824
Tokenizer(const Tokenizer &);
@@ -852,6 +860,7 @@ class CPPCHECKLIB Tokenizer {
852860
* TimerResults
853861
*/
854862
TimerResults *m_timerResults;
863+
855864
#ifdef MAXTIME
856865
/** Tokenizer maxtime */
857866
std::time_t maxtime;

0 commit comments

Comments
 (0)