From 34468f3c1abb5aa782def5550b54f2c2f7cfb990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 24 Jun 2020 20:30:03 +0200 Subject: [PATCH] Template simplifier; Write information message when recursion limit is reached. --- lib/settings.cpp | 1 + lib/settings.h | 7 +++++-- lib/templatesimplifier.cpp | 14 +++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/settings.cpp b/lib/settings.cpp index dd7760950..bb725785d 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -57,6 +57,7 @@ Settings::Settings() loadAverage(0), maxConfigs(12), maxCtuDepth(2), + maxTemplateRecursion(100), preprocessOnly(false), quiet(false), relativePaths(false), diff --git a/lib/settings.h b/lib/settings.h index 725885ddd..14132e786 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -202,15 +202,18 @@ public: Library library; /** @brief Load average value */ - unsigned int loadAverage; + int loadAverage; /** @brief Maximum number of configurations to check before bailing. Default is 12. (--max-configs=N) */ - unsigned int maxConfigs; + int maxConfigs; /** @brief --max-ctu-depth */ int maxCtuDepth; + /** @brief max template recursion */ + int maxTemplateRecursion; + /** @brief suppress exitcode */ Suppressions nofail; diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index a92c9a130..7119e036f 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2929,7 +2929,19 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( if (numberOfTemplateInstantiations != mTemplateInstantiations.size()) { numberOfTemplateInstantiations = mTemplateInstantiations.size(); ++recursiveCount; - if (recursiveCount > 100) { + if (recursiveCount > mSettings->maxTemplateRecursion) { + const std::list callstack(1, instantiation.token()); + const ErrorMessage errmsg(callstack, + &mTokenizer->list, + Severity::information, + "templateRecursion", + "TemplateSimplifier: max template recursion (" + + MathLib::toString(mSettings->maxTemplateRecursion) + + ") reached for template '"+instantiation.fullName()+"'. You might want to limit Cppcheck recursion.", + false); + if (mErrorLogger && mSettings->isEnabled(Settings::INFORMATION)) + mErrorLogger->reportErr(errmsg); + // bail out.. break; }