1818
1919#include " checkboost.h"
2020
21+ #include " checkimpl.h"
2122#include " errortypes.h"
2223#include " symboldatabase.h"
2324#include " token.h"
@@ -31,7 +32,20 @@ namespace {
3132
3233static const CWE CWE664 (664 );
3334
34- void CheckBoost::checkBoostForeachModification ()
35+ class CheckBoostImpl : public CheckImpl
36+ {
37+ public:
38+ /* * This constructor is used when running checks. */
39+ CheckBoostImpl (const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
40+ : CheckImpl(tokenizer, settings, errorLogger) {}
41+
42+ /* * @brief %Check for container modification while using the BOOST_FOREACH macro */
43+ void checkBoostForeachModification ();
44+
45+ void boostForeachError (const Token *tok);
46+ };
47+
48+ void CheckBoostImpl::checkBoostForeachModification ()
3549{
3650 const SymbolDatabase *symbolDatabase = mTokenizer ->getSymbolDatabase ();
3751 for (const Scope * scope : symbolDatabase->functionScopes ) {
@@ -57,9 +71,24 @@ void CheckBoost::checkBoostForeachModification()
5771 }
5872}
5973
60- void CheckBoost ::boostForeachError (const Token *tok)
74+ void CheckBoostImpl ::boostForeachError (const Token *tok)
6175{
6276 reportError (tok, Severity::error, " boostForeachError" ,
6377 " BOOST_FOREACH caches the end() iterator. It's undefined behavior if you modify the container inside." , CWE664, Certainty::normal
6478 );
6579}
80+
81+ void CheckBoost::runChecks (const Tokenizer &tokenizer, ErrorLogger *errorLogger)
82+ {
83+ if (!tokenizer.isCPP ())
84+ return ;
85+
86+ CheckBoostImpl checkBoost (&tokenizer, tokenizer.getSettings (), errorLogger);
87+ checkBoost.checkBoostForeachModification ();
88+ }
89+
90+ void CheckBoost::getErrorMessages (ErrorLogger *errorLogger, const Settings *settings) const
91+ {
92+ CheckBoostImpl c (nullptr , settings, errorLogger);
93+ c.boostForeachError (nullptr );
94+ }
0 commit comments