1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2021 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 
20 //---------------------------------------------------------------------------
21 #ifndef check64bitH
22 #define check64bitH
23 //---------------------------------------------------------------------------
24 
25 #include "check.h"
26 #include "config.h"
27 
28 #include <string>
29 
30 class ErrorLogger;
31 class Settings;
32 class Token;
33 class Tokenizer;
34 
35 
36 /// @addtogroup Checks
37 /// @{
38 
39 /**
40  * @brief Check for 64-bit portability issues
41  */
42 
43 class CPPCHECKLIB Check64BitPortability : public Check {
44 public:
45     /** This constructor is used when registering the Check64BitPortability */
Check64BitPortability()46     Check64BitPortability() : Check(myName()) {}
47 
48     /** This constructor is used when running checks. */
Check64BitPortability(const Tokenizer * tokenizer,const Settings * settings,ErrorLogger * errorLogger)49     Check64BitPortability(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
50         : Check(myName(), tokenizer, settings, errorLogger) {}
51 
52     /** @brief Run checks against the normal token list */
runChecks(const Tokenizer * tokenizer,const Settings * settings,ErrorLogger * errorLogger)53     void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) OVERRIDE {
54         Check64BitPortability check64BitPortability(tokenizer, settings, errorLogger);
55         check64BitPortability.pointerassignment();
56     }
57 
58     /** Check for pointer assignment */
59     void pointerassignment();
60 
61 private:
62 
63     void assignmentAddressToIntegerError(const Token *tok);
64     void assignmentIntegerToAddressError(const Token *tok);
65     void returnIntegerError(const Token *tok);
66     void returnPointerError(const Token *tok);
67 
getErrorMessages(ErrorLogger * errorLogger,const Settings * settings)68     void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const OVERRIDE {
69         Check64BitPortability c(nullptr, settings, errorLogger);
70         c.assignmentAddressToIntegerError(nullptr);
71         c.assignmentIntegerToAddressError(nullptr);
72         c.returnIntegerError(nullptr);
73         c.returnPointerError(nullptr);
74     }
75 
myName()76     static std::string myName() {
77         return "64-bit portability";
78     }
79 
classInfo()80     std::string classInfo() const OVERRIDE {
81         return "Check if there is 64-bit portability issues:\n"
82                "- assign address to/from int/long\n"
83                "- casting address from/to integer when returning from function\n";
84     }
85 };
86 /// @}
87 //---------------------------------------------------------------------------
88 #endif // check64bitH
89