Cppcheck
check64bit.h
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2024 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 #include "tokenize.h"
28 
29 #include <string>
30 
31 class ErrorLogger;
32 class Settings;
33 class Token;
34 
35 
36 /// @addtogroup Checks
37 /// @{
38 
39 /**
40  * @brief Check for 64-bit portability issues
41  */
42 
44  friend class Test64BitPortability;
45 
46 public:
47  /** This constructor is used when registering the Check64BitPortability */
48  Check64BitPortability() : Check(myName()) {}
49 
50 private:
51  /** This constructor is used when running checks. */
52  Check64BitPortability(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
53  : Check(myName(), tokenizer, settings, errorLogger) {}
54 
55  /** @brief Run checks against the normal token list */
56  void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
57  Check64BitPortability check64BitPortability(&tokenizer, &tokenizer.getSettings(), errorLogger);
58  check64BitPortability.pointerassignment();
59  }
60 
61  /** Check for pointer assignment */
62  void pointerassignment();
63 
64  void assignmentAddressToIntegerError(const Token *tok);
65  void assignmentIntegerToAddressError(const Token *tok);
66  void returnIntegerError(const Token *tok);
67  void returnPointerError(const Token *tok);
68 
69  void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
70  Check64BitPortability c(nullptr, settings, errorLogger);
73  c.returnIntegerError(nullptr);
74  c.returnPointerError(nullptr);
75  }
76 
77  static std::string myName() {
78  return "64-bit portability";
79  }
80 
81  std::string classInfo() const override {
82  return "Check if there is 64-bit portability issues:\n"
83  "- assign address to/from int/long\n"
84  "- casting address from/to integer when returning from function\n";
85  }
86 };
87 /// @}
88 //---------------------------------------------------------------------------
89 #endif // check64bitH
Check for 64-bit portability issues.
Definition: check64bit.h:43
void assignmentAddressToIntegerError(const Token *tok)
Definition: check64bit.cpp:121
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override
Run checks against the normal token list.
Definition: check64bit.h:56
void returnIntegerError(const Token *tok)
Definition: check64bit.cpp:154
Check64BitPortability()
This constructor is used when registering the Check64BitPortability.
Definition: check64bit.h:48
void assignmentIntegerToAddressError(const Token *tok)
Definition: check64bit.cpp:132
std::string classInfo() const override
get information about this class, used to generate documentation
Definition: check64bit.h:81
void returnPointerError(const Token *tok)
Definition: check64bit.cpp:143
Check64BitPortability(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
This constructor is used when running checks.
Definition: check64bit.h:52
void pointerassignment()
Check for pointer assignment.
Definition: check64bit.cpp:43
static std::string myName()
Definition: check64bit.h:77
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override
get error messages
Definition: check64bit.h:69
Interface class that cppcheck uses to communicate with the checks.
Definition: check.h:59
This is an interface, which the class responsible of error logging should implement.
Definition: errorlogger.h:214
This is just a container for general settings so that we don't need to pass individual values to func...
Definition: settings.h:95
The token list that the TokenList generates is a linked-list of this class.
Definition: token.h:150
The main purpose is to tokenize the source code.
Definition: tokenize.h:46
const Settings & getSettings() const
Definition: tokenize.h:615
#define CPPCHECKLIB
Definition: config.h:35