2222
2323#include " check64bit.h"
2424
25+ #include " checkimpl.h"
2526#include " errortypes.h"
2627#include " settings.h"
2728#include " symboldatabase.h"
@@ -40,7 +41,22 @@ namespace {
4041 Check64BitPortability instance;
4142}
4243
43- void Check64BitPortability::pointerassignment ()
44+ class Check64BitPortabilityImpl : public CheckImpl {
45+ public:
46+ /* * This constructor is used when running checks. */
47+ Check64BitPortabilityImpl (const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
48+ : CheckImpl(tokenizer, settings, errorLogger) {}
49+
50+ /* * Check for pointer assignment */
51+ void pointerassignment ();
52+
53+ void assignmentAddressToIntegerError (const Token *tok);
54+ void assignmentIntegerToAddressError (const Token *tok);
55+ void returnIntegerError (const Token *tok);
56+ void returnPointerError (const Token *tok);
57+ };
58+
59+ void Check64BitPortabilityImpl::pointerassignment ()
4460{
4561 if (!mSettings ->severity .isEnabled (Severity::portability))
4662 return ;
@@ -118,7 +134,7 @@ void Check64BitPortability::pointerassignment()
118134 }
119135}
120136
121- void Check64BitPortability ::assignmentAddressToIntegerError (const Token *tok)
137+ void Check64BitPortabilityImpl ::assignmentAddressToIntegerError (const Token *tok)
122138{
123139 reportError (tok, Severity::portability,
124140 " AssignmentAddressToInteger" ,
@@ -129,7 +145,7 @@ void Check64BitPortability::assignmentAddressToIntegerError(const Token *tok)
129145 " way is to store addresses only in pointer types (or typedefs like uintptr_t)." , CWE758, Certainty::normal);
130146}
131147
132- void Check64BitPortability ::assignmentIntegerToAddressError (const Token *tok)
148+ void Check64BitPortabilityImpl ::assignmentIntegerToAddressError (const Token *tok)
133149{
134150 reportError (tok, Severity::portability,
135151 " AssignmentIntegerToAddress" ,
@@ -140,7 +156,7 @@ void Check64BitPortability::assignmentIntegerToAddressError(const Token *tok)
140156 " way is to store addresses only in pointer types (or typedefs like uintptr_t)." , CWE758, Certainty::normal);
141157}
142158
143- void Check64BitPortability ::returnPointerError (const Token *tok)
159+ void Check64BitPortabilityImpl ::returnPointerError (const Token *tok)
144160{
145161 reportError (tok, Severity::portability,
146162 " CastAddressToIntegerAtReturn" ,
@@ -151,7 +167,7 @@ void Check64BitPortability::returnPointerError(const Token *tok)
151167 " to 32-bit integer. The safe way is to always return an integer." , CWE758, Certainty::normal);
152168}
153169
154- void Check64BitPortability ::returnIntegerError (const Token *tok)
170+ void Check64BitPortabilityImpl ::returnIntegerError (const Token *tok)
155171{
156172 reportError (tok, Severity::portability,
157173 " CastIntegerToAddressAtReturn" ,
@@ -161,3 +177,20 @@ void Check64BitPortability::returnIntegerError(const Token *tok)
161177 " and Linux they are of different width. In worst case you end up casting 64-bit integer down to 32-bit pointer. "
162178 " The safe way is to always return a pointer." , CWE758, Certainty::normal);
163179}
180+
181+
182+ /* * @brief Run checks against the normal token list */
183+ void Check64BitPortability::runChecks (const Tokenizer &tokenizer, ErrorLogger *errorLogger)
184+ {
185+ Check64BitPortabilityImpl c (&tokenizer, tokenizer.getSettings (), errorLogger);
186+ c.pointerassignment ();
187+ }
188+
189+ void Check64BitPortability::getErrorMessages (ErrorLogger *errorLogger, const Settings *settings) const
190+ {
191+ Check64BitPortabilityImpl c (nullptr , settings, errorLogger);
192+ c.assignmentAddressToIntegerError (nullptr );
193+ c.assignmentIntegerToAddressError (nullptr );
194+ c.returnIntegerError (nullptr );
195+ c.returnPointerError (nullptr );
196+ }
0 commit comments