2222
2323#include " check64bit.h"
2424
25+ #include " checkimpl.h"
2526#include " errortypes.h"
2627#include " settings.h"
2728#include " symboldatabase.h"
@@ -41,7 +42,22 @@ namespace {
4142 Check64BitPortability instance;
4243}
4344
44- void Check64BitPortability::pointerassignment ()
45+ class Check64BitPortabilityImpl : public CheckImpl {
46+ public:
47+ /* * This constructor is used when running checks. */
48+ Check64BitPortabilityImpl (const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
49+ : CheckImpl(tokenizer, settings, errorLogger) {}
50+
51+ /* * Check for pointer assignment */
52+ void pointerassignment ();
53+
54+ void assignmentAddressToIntegerError (const Token *tok);
55+ void assignmentIntegerToAddressError (const Token *tok);
56+ void returnIntegerError (const Token *tok);
57+ void returnPointerError (const Token *tok);
58+ };
59+
60+ void Check64BitPortabilityImpl::pointerassignment ()
4561{
4662 if (!mSettings ->severity .isEnabled (Severity::portability))
4763 return ;
@@ -117,7 +133,7 @@ void Check64BitPortability::pointerassignment()
117133 }
118134}
119135
120- void Check64BitPortability ::assignmentAddressToIntegerError (const Token *tok)
136+ void Check64BitPortabilityImpl ::assignmentAddressToIntegerError (const Token *tok)
121137{
122138 reportError (tok, Severity::portability,
123139 " AssignmentAddressToInteger" ,
@@ -128,7 +144,7 @@ void Check64BitPortability::assignmentAddressToIntegerError(const Token *tok)
128144 " way is to store addresses only in pointer types (or typedefs like uintptr_t)." , CWE758, Certainty::normal);
129145}
130146
131- void Check64BitPortability ::assignmentIntegerToAddressError (const Token *tok)
147+ void Check64BitPortabilityImpl ::assignmentIntegerToAddressError (const Token *tok)
132148{
133149 reportError (tok, Severity::portability,
134150 " AssignmentIntegerToAddress" ,
@@ -139,7 +155,7 @@ void Check64BitPortability::assignmentIntegerToAddressError(const Token *tok)
139155 " way is to store addresses only in pointer types (or typedefs like uintptr_t)." , CWE758, Certainty::normal);
140156}
141157
142- void Check64BitPortability ::returnPointerError (const Token *tok)
158+ void Check64BitPortabilityImpl ::returnPointerError (const Token *tok)
143159{
144160 reportError (tok, Severity::portability,
145161 " CastAddressToIntegerAtReturn" ,
@@ -150,7 +166,7 @@ void Check64BitPortability::returnPointerError(const Token *tok)
150166 " to 32-bit integer. The safe way is to always return an integer." , CWE758, Certainty::normal);
151167}
152168
153- void Check64BitPortability ::returnIntegerError (const Token *tok)
169+ void Check64BitPortabilityImpl ::returnIntegerError (const Token *tok)
154170{
155171 reportError (tok, Severity::portability,
156172 " CastIntegerToAddressAtReturn" ,
@@ -160,3 +176,20 @@ void Check64BitPortability::returnIntegerError(const Token *tok)
160176 " and Linux they are of different width. In worst case you end up casting 64-bit integer down to 32-bit pointer. "
161177 " The safe way is to always return a pointer." , CWE758, Certainty::normal);
162178}
179+
180+
181+ /* * @brief Run checks against the normal token list */
182+ void Check64BitPortability::runChecks (const Tokenizer &tokenizer, ErrorLogger *errorLogger)
183+ {
184+ Check64BitPortabilityImpl c (&tokenizer, tokenizer.getSettings (), errorLogger);
185+ c.pointerassignment ();
186+ }
187+
188+ void Check64BitPortability::getErrorMessages (ErrorLogger *errorLogger, const Settings *settings) const
189+ {
190+ Check64BitPortabilityImpl c (nullptr , settings, errorLogger);
191+ c.assignmentAddressToIntegerError (nullptr );
192+ c.assignmentIntegerToAddressError (nullptr );
193+ c.returnIntegerError (nullptr );
194+ c.returnPointerError (nullptr );
195+ }
0 commit comments