/src/cppcheck/lib/checkvaarg.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- C++ -*- |
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 checkvaargtH |
22 | | #define checkvaargtH |
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 | | /// @addtogroup Checks |
36 | | /// @{ |
37 | | |
38 | | /** |
39 | | * @brief Checking for misusage of variable argument lists |
40 | | */ |
41 | | |
42 | | class CPPCHECKLIB CheckVaarg : public Check { |
43 | | public: |
44 | 2 | CheckVaarg() : Check(myName()) {} |
45 | | |
46 | | private: |
47 | | CheckVaarg(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) |
48 | 763 | : Check(myName(), tokenizer, settings, errorLogger) {} |
49 | | |
50 | | void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override; |
51 | | |
52 | | void va_start_argument(); |
53 | | void va_list_usage(); |
54 | | |
55 | | void wrongParameterTo_va_start_error(const Token *tok, const std::string& paramIsName, const std::string& paramShouldName); |
56 | | void referenceAs_va_start_error(const Token *tok, const std::string& paramName); |
57 | | void va_end_missingError(const Token *tok, const std::string& varname); |
58 | | void va_list_usedBeforeStartedError(const Token *tok, const std::string& varname); |
59 | | void va_start_subsequentCallsError(const Token *tok, const std::string& varname); |
60 | | |
61 | | void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; |
62 | | |
63 | 765 | static std::string myName() { |
64 | 765 | return "Vaarg"; |
65 | 765 | } |
66 | | |
67 | 0 | std::string classInfo() const override { |
68 | 0 | return "Check for misusage of variable argument lists:\n" |
69 | 0 | "- Wrong parameter passed to va_start()\n" |
70 | 0 | "- Reference passed to va_start()\n" |
71 | 0 | "- Missing va_end()\n" |
72 | 0 | "- Using va_list before it is opened\n" |
73 | 0 | "- Subsequent calls to va_start/va_copy()\n"; |
74 | 0 | } |
75 | | }; |
76 | | |
77 | | /// @} |
78 | | |
79 | | //--------------------------------------------------------------------------- |
80 | | #endif // checkvaargtH |