Cppcheck
checkother.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 checkotherH
22 #define checkotherH
23 //---------------------------------------------------------------------------
24 
25 #include "check.h"
26 #include "config.h"
27 #include "errortypes.h"
28 #include "tokenize.h"
29 
30 #include <string>
31 #include <vector>
32 
33 namespace ValueFlow {
34  class Value;
35 }
36 
37 class Settings;
38 class Token;
39 class Function;
40 class Variable;
41 class ErrorLogger;
42 
43 /// @addtogroup Checks
44 /// @{
45 
46 
47 /** @brief Various small checks */
48 
49 class CPPCHECKLIB CheckOther : public Check {
50  friend class TestCharVar;
51  friend class TestIncompleteStatement;
52  friend class TestOther;
53 
54 public:
55  /** @brief This constructor is used when registering the CheckClass */
56  CheckOther() : Check(myName()) {}
57 
58  /** Is expression a comparison that checks if a nonzero (unsigned/pointer) expression is less than zero? */
59  static bool comparisonNonZeroExpressionLessThanZero(const Token *tok, const ValueFlow::Value *&zeroValue, const Token *&nonZeroExpr, bool suppress = false);
60 
61  /** Is expression a comparison that checks if a nonzero (unsigned/pointer) expression is positive? */
62  static bool testIfNonZeroExpressionIsPositive(const Token *tok, const ValueFlow::Value *&zeroValue, const Token *&nonZeroExpr);
63 
64 private:
65  /** @brief This constructor is used when running checks. */
66  CheckOther(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
67  : Check(myName(), tokenizer, settings, errorLogger) {}
68 
69 
70  /** @brief Run checks against the normal token list */
71  void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
72  CheckOther checkOther(&tokenizer, &tokenizer.getSettings(), errorLogger);
73 
74  // Checks
75  checkOther.warningOldStylePointerCast();
76  checkOther.invalidPointerCast();
77  checkOther.checkCharVariable();
78  checkOther.checkRedundantAssignment();
80  checkOther.checkSuspiciousCaseInSwitch();
81  checkOther.checkDuplicateBranch();
82  checkOther.checkDuplicateExpression();
83  checkOther.checkUnreachableCode();
84  checkOther.checkSuspiciousSemicolon();
85  checkOther.checkVariableScope();
86  checkOther.checkSignOfUnsignedVariable(); // don't ignore casts (#3574)
87  checkOther.checkIncompleteArrayFill();
88  checkOther.checkVarFuncNullUB();
89  checkOther.checkNanInArithmeticExpression();
90  checkOther.checkCommaSeparatedReturn();
91  checkOther.checkRedundantPointerOp();
92  checkOther.checkZeroDivision();
93  checkOther.checkNegativeBitwiseShift();
94  checkOther.checkInterlockedDecrement();
95  checkOther.checkUnusedLabel();
96  checkOther.checkEvaluationOrder();
97  checkOther.checkFuncArgNamesDifferent();
98  checkOther.checkShadowVariables();
99  checkOther.checkKnownArgument();
100  checkOther.checkKnownPointerToBool();
101  checkOther.checkComparePointers();
102  checkOther.checkIncompleteStatement();
103  checkOther.checkRedundantCopy();
104  checkOther.clarifyCalculation();
105  checkOther.checkPassByReference();
106  checkOther.checkConstVariable();
107  checkOther.checkConstPointer();
109  checkOther.checkInvalidFree();
110  checkOther.clarifyStatement();
111  checkOther.checkCastIntToCharAndBack();
112  checkOther.checkMisusedScopedObject();
113  checkOther.checkAccessOfMovedVariable();
114  checkOther.checkModuloOfOne();
115  checkOther.checkOverlappingWrite();
116  }
117 
118  /** @brief Clarify calculation for ".. a * b ? .." */
119  void clarifyCalculation();
120 
121  /** @brief Suspicious statement like '*A++;' */
122  void clarifyStatement();
123 
124  /** @brief Are there C-style pointer casts in a c++ file? */
125  void warningOldStylePointerCast();
126 
127  /** @brief Check for pointer casts to a type with an incompatible binary data representation */
128  void invalidPointerCast();
129 
130  /** @brief %Check scope of variables */
131  void checkVariableScope();
132  bool checkInnerScope(const Token *tok, const Variable* var, bool& used) const;
133 
134  /** @brief %Check for comma separated statements in return */
135  void checkCommaSeparatedReturn();
136 
137  /** @brief %Check for function parameters that should be passed by reference */
138  void checkPassByReference();
139 
140  void checkConstVariable();
141  void checkConstPointer();
142 
143  /** @brief Using char variable as array index / as operand in bit operation */
144  void checkCharVariable();
145 
146  /** @brief Incomplete statement. A statement that only contains a constant or variable */
147  void checkIncompleteStatement();
148 
149  /** @brief %Check zero division*/
150  void checkZeroDivision();
151 
152  /** @brief Check for NaN (not-a-number) in an arithmetic expression */
153  void checkNanInArithmeticExpression();
154 
155  /** @brief copying to memory or assigning to a variable twice */
156  void checkRedundantAssignment();
157 
158  /** @brief %Check for redundant bitwise operation in switch statement*/
159  void redundantBitwiseOperationInSwitchError();
160 
161  /** @brief %Check for code like 'case A||B:'*/
162  void checkSuspiciousCaseInSwitch();
163 
164  /** @brief %Check for objects that are destroyed immediately */
165  void checkMisusedScopedObject();
166 
167  /** @brief %Check for suspicious code where if and else branch are the same (e.g "if (a) b = true; else b = true;") */
168  void checkDuplicateBranch();
169 
170  /** @brief %Check for suspicious code with the same expression on both sides of operator (e.g "if (a && a)") */
171  void checkDuplicateExpression();
172 
173  /** @brief %Check for code that gets never executed, such as duplicate break statements */
174  void checkUnreachableCode();
175 
176  /** @brief %Check for testing sign of unsigned variable */
177  void checkSignOfUnsignedVariable();
178 
179  /** @brief %Check for suspicious use of semicolon */
180  void checkSuspiciousSemicolon();
181 
182  /** @brief %Check for free() operations on invalid memory locations */
183  void checkInvalidFree();
184  void invalidFreeError(const Token *tok, const std::string &allocation, bool inconclusive);
185 
186  /** @brief %Check for code creating redundant copies */
187  void checkRedundantCopy();
188 
189  /** @brief %Check for bitwise shift with negative right operand */
190  void checkNegativeBitwiseShift();
191 
192  /** @brief %Check for buffers that are filled incompletely with memset and similar functions */
193  void checkIncompleteArrayFill();
194 
195  /** @brief %Check that variadic function calls don't use NULL. If NULL is \#defined as 0 and the function expects a pointer, the behaviour is undefined. */
196  void checkVarFuncNullUB();
197 
198  /** @brief %Check to avoid casting a return value to unsigned char and then back to integer type. */
199  void checkCastIntToCharAndBack();
200 
201  /** @brief %Check for using of comparison functions evaluating always to true or false. */
202  void checkComparisonFunctionIsAlwaysTrueOrFalse();
203 
204  /** @brief %Check for redundant pointer operations */
205  void checkRedundantPointerOp();
206 
207  /** @brief %Check for race condition with non-interlocked access after InterlockedDecrement() */
208  void checkInterlockedDecrement();
209 
210  /** @brief %Check for unused labels */
211  void checkUnusedLabel();
212 
213  /** @brief %Check for expression that depends on order of evaluation of side effects */
214  void checkEvaluationOrder();
215 
216  /** @brief %Check for access of moved or forwarded variable */
217  void checkAccessOfMovedVariable();
218 
219  /** @brief %Check if function declaration and definition argument names different */
220  void checkFuncArgNamesDifferent();
221 
222  /** @brief %Check for shadow variables. Less noisy than gcc/clang -Wshadow. */
223  void checkShadowVariables();
224 
225  void checkKnownArgument();
226 
227  void checkKnownPointerToBool();
228 
229  void checkComparePointers();
230 
231  void checkModuloOfOne();
232 
233  void checkOverlappingWrite();
234  void overlappingWriteUnion(const Token *tok);
235  void overlappingWriteFunction(const Token *tok);
236 
237  // Error messages..
238  void checkComparisonFunctionIsAlwaysTrueOrFalseError(const Token* tok, const std::string &functionName, const std::string &varName, const bool result);
239  void checkCastIntToCharAndBackError(const Token *tok, const std::string &strFunctionName);
240  void clarifyCalculationError(const Token *tok, const std::string &op);
241  void clarifyStatementError(const Token* tok);
242  void cstyleCastError(const Token *tok, bool isPtr = true);
243  void invalidPointerCastError(const Token* tok, const std::string& from, const std::string& to, bool inconclusive, bool toIsInt);
244  void passedByValueError(const Variable* var, bool inconclusive, bool isRangeBasedFor = false);
245  void constVariableError(const Variable *var, const Function *function);
246  void constStatementError(const Token *tok, const std::string &type, bool inconclusive);
247  void signedCharArrayIndexError(const Token *tok);
248  void unknownSignCharArrayIndexError(const Token *tok);
249  void charBitOpError(const Token *tok);
250  void variableScopeError(const Token *tok, const std::string &varname);
251  void zerodivError(const Token *tok, const ValueFlow::Value *value);
252  void nanInArithmeticExpressionError(const Token *tok);
253  void redundantAssignmentError(const Token *tok1, const Token* tok2, const std::string& var, bool inconclusive);
254  void redundantInitializationError(const Token *tok1, const Token* tok2, const std::string& var, bool inconclusive);
255  void redundantAssignmentInSwitchError(const Token *tok1, const Token *tok2, const std::string &var);
256  void redundantCopyError(const Token *tok1, const Token* tok2, const std::string& var);
257  void redundantBitwiseOperationInSwitchError(const Token *tok, const std::string &varname);
258  void suspiciousCaseInSwitchError(const Token* tok, const std::string& operatorString);
259  void selfAssignmentError(const Token *tok, const std::string &varname);
260  void misusedScopeObjectError(const Token *tok, const std::string &varname, bool isAssignment = false);
261  void duplicateBranchError(const Token *tok1, const Token *tok2, ErrorPath errors);
262  void duplicateAssignExpressionError(const Token *tok1, const Token *tok2, bool inconclusive);
263  void oppositeExpressionError(const Token *opTok, ErrorPath errors);
264  void duplicateExpressionError(const Token *tok1, const Token *tok2, const Token *opTok, ErrorPath errors, bool hasMultipleExpr = false);
265  void duplicateValueTernaryError(const Token *tok);
266  void duplicateExpressionTernaryError(const Token *tok, ErrorPath errors);
267  void duplicateBreakError(const Token *tok, bool inconclusive);
268  void unreachableCodeError(const Token* tok, const Token* noreturn, bool inconclusive);
269  void redundantContinueError(const Token* tok);
270  void unsignedLessThanZeroError(const Token *tok, const ValueFlow::Value *v, const std::string &varname);
271  void pointerLessThanZeroError(const Token *tok, const ValueFlow::Value *v);
272  void unsignedPositiveError(const Token *tok, const ValueFlow::Value *v, const std::string &varname);
273  void pointerPositiveError(const Token *tok, const ValueFlow::Value *v);
274  void suspiciousSemicolonError(const Token *tok);
275  void negativeBitwiseShiftError(const Token *tok, int op);
276  void redundantCopyError(const Token *tok, const std::string &varname);
277  void incompleteArrayFillError(const Token* tok, const std::string& buffer, const std::string& function, bool boolean);
278  void varFuncNullUBError(const Token *tok);
279  void commaSeparatedReturnError(const Token *tok);
280  void redundantPointerOpError(const Token* tok, const std::string& varname, bool inconclusive, bool addressOfDeref);
281  void raceAfterInterlockedDecrementError(const Token* tok);
282  void unusedLabelError(const Token* tok, bool inSwitch, bool hasIfdef);
283  void unknownEvaluationOrder(const Token* tok);
284  void accessMovedError(const Token *tok, const std::string &varname, const ValueFlow::Value *value, bool inconclusive);
285  void funcArgNamesDifferent(const std::string & functionName, nonneg int index, const Token* declaration, const Token* definition);
286  void funcArgOrderDifferent(const std::string & functionName, const Token * declaration, const Token * definition, const std::vector<const Token*> & declarations, const std::vector<const Token*> & definitions);
287  void shadowError(const Token *var, const Token *shadowed, const std::string& type);
288  void knownArgumentError(const Token *tok, const Token *ftok, const ValueFlow::Value *value, const std::string &varexpr, bool isVariableExpressionHidden);
289  void knownPointerToBoolError(const Token* tok, const ValueFlow::Value* value);
290  void comparePointersError(const Token *tok, const ValueFlow::Value *v1, const ValueFlow::Value *v2);
291  void checkModuloOfOneError(const Token *tok);
292 
293  void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
294  CheckOther c(nullptr, settings, errorLogger);
295 
296  // error
297  c.zerodivError(nullptr, nullptr);
298  c.misusedScopeObjectError(nullptr, "varname");
299  c.invalidPointerCastError(nullptr, "float *", "double *", false, false);
300  c.negativeBitwiseShiftError(nullptr, 1);
301  c.negativeBitwiseShiftError(nullptr, 2);
303  c.invalidFreeError(nullptr, "malloc", false);
304  c.overlappingWriteUnion(nullptr);
305  c.overlappingWriteFunction(nullptr);
306 
307  //performance
308  c.redundantCopyError(nullptr, "varname");
309  c.redundantCopyError(nullptr, nullptr, "var");
310 
311  // style/warning
312  c.checkComparisonFunctionIsAlwaysTrueOrFalseError(nullptr, "isless","varName",false);
313  c.checkCastIntToCharAndBackError(nullptr, "func_name");
314  c.cstyleCastError(nullptr);
315  c.passedByValueError(nullptr, false);
316  c.constVariableError(nullptr, nullptr);
317  c.constStatementError(nullptr, "type", false);
318  c.signedCharArrayIndexError(nullptr);
320  c.charBitOpError(nullptr);
321  c.variableScopeError(nullptr, "varname");
322  c.redundantAssignmentInSwitchError(nullptr, nullptr, "var");
323  c.suspiciousCaseInSwitchError(nullptr, "||");
324  c.selfAssignmentError(nullptr, "varname");
325  c.clarifyCalculationError(nullptr, "+");
326  c.clarifyStatementError(nullptr);
327  c.duplicateBranchError(nullptr, nullptr, ErrorPath{});
328  c.duplicateAssignExpressionError(nullptr, nullptr, true);
329  c.oppositeExpressionError(nullptr, ErrorPath{});
330  c.duplicateExpressionError(nullptr, nullptr, nullptr, ErrorPath{});
331  c.duplicateValueTernaryError(nullptr);
333  c.duplicateBreakError(nullptr, false);
334  c.unreachableCodeError(nullptr, nullptr, false);
335  c.unsignedLessThanZeroError(nullptr, nullptr, "varname");
336  c.unsignedPositiveError(nullptr, nullptr, "varname");
337  c.pointerLessThanZeroError(nullptr, nullptr);
338  c.pointerPositiveError(nullptr, nullptr);
339  c.suspiciousSemicolonError(nullptr);
340  c.incompleteArrayFillError(nullptr, "buffer", "memset", false);
341  c.varFuncNullUBError(nullptr);
343  c.commaSeparatedReturnError(nullptr);
344  c.redundantPointerOpError(nullptr, "varname", false, /*addressOfDeref*/ true);
345  c.unusedLabelError(nullptr, false, false);
346  c.unusedLabelError(nullptr, false, true);
347  c.unusedLabelError(nullptr, true, false);
348  c.unusedLabelError(nullptr, true, true);
349  c.unknownEvaluationOrder(nullptr);
350  c.accessMovedError(nullptr, "v", nullptr, false);
351  c.funcArgNamesDifferent("function", 1, nullptr, nullptr);
352  c.redundantBitwiseOperationInSwitchError(nullptr, "varname");
353  c.shadowError(nullptr, nullptr, "variable");
354  c.shadowError(nullptr, nullptr, "function");
355  c.shadowError(nullptr, nullptr, "argument");
356  c.knownArgumentError(nullptr, nullptr, nullptr, "x", false);
357  c.knownPointerToBoolError(nullptr, nullptr);
358  c.comparePointersError(nullptr, nullptr, nullptr);
359  c.redundantAssignmentError(nullptr, nullptr, "var", false);
360  c.redundantInitializationError(nullptr, nullptr, "var", false);
361 
362  const std::vector<const Token *> nullvec;
363  c.funcArgOrderDifferent("function", nullptr, nullptr, nullvec, nullvec);
364  c.checkModuloOfOneError(nullptr);
365  }
366 
367  static std::string myName() {
368  return "Other";
369  }
370 
371  std::string classInfo() const override {
372  return "Other checks\n"
373 
374  // error
375  "- division with zero\n"
376  "- scoped object destroyed immediately after construction\n"
377  "- assignment in an assert statement\n"
378  "- free() or delete of an invalid memory location\n"
379  "- bitwise operation with negative right operand\n"
380  "- cast the return values of getc(),fgetc() and getchar() to character and compare it to EOF\n"
381  "- race condition with non-interlocked access after InterlockedDecrement() call\n"
382  "- expression 'x = x++;' depends on order of evaluation of side effects\n"
383  "- overlapping write of union\n"
384 
385  // warning
386  "- either division by zero or useless condition\n"
387  "- access of moved or forwarded variable.\n"
388 
389  // performance
390  "- redundant data copying for const variable\n"
391  "- subsequent assignment or copying to a variable or buffer\n"
392  "- passing parameter by value\n"
393 
394  // portability
395  "- Passing NULL pointer to function with variable number of arguments leads to UB.\n"
396 
397  // style
398  "- C-style pointer cast in C++ code\n"
399  "- casting between incompatible pointer types\n"
400  "- [Incomplete statement](IncompleteStatement)\n"
401  "- [check how signed char variables are used](CharVar)\n"
402  "- variable scope can be limited\n"
403  "- unusual pointer arithmetic. For example: \"abc\" + 'd'\n"
404  "- redundant assignment, increment, or bitwise operation in a switch statement\n"
405  "- redundant strcpy in a switch statement\n"
406  "- Suspicious case labels in switch()\n"
407  "- assignment of a variable to itself\n"
408  "- Comparison of values leading always to true or false\n"
409  "- Clarify calculation with parentheses\n"
410  "- suspicious comparison of '\\0' with a char\\* variable\n"
411  "- duplicate break statement\n"
412  "- unreachable code\n"
413  "- testing if unsigned variable is negative/positive\n"
414  "- Suspicious use of ; at the end of 'if/for/while' statement.\n"
415  "- Array filled incompletely using memset/memcpy/memmove.\n"
416  "- NaN (not a number) value used in arithmetic expression.\n"
417  "- comma in return statement (the comma can easily be misread as a semicolon).\n"
418  "- prefer erfc, expm1 or log1p to avoid loss of precision.\n"
419  "- identical code in both branches of if/else or ternary operator.\n"
420  "- redundant pointer operation on pointer like &\\*some_ptr.\n"
421  "- find unused 'goto' labels.\n"
422  "- function declaration and definition argument names different.\n"
423  "- function declaration and definition argument order different.\n"
424  "- shadow variable.\n"
425  "- variable can be declared const.\n"
426  "- calculating modulo of one.\n"
427  "- known function argument, suspicious calculation.\n";
428  }
429 };
430 /// @}
431 //---------------------------------------------------------------------------
432 #endif // checkotherH
Various small checks.
Definition: checkother.h:49
void checkModuloOfOne()
void unknownEvaluationOrder(const Token *tok)
void cstyleCastError(const Token *tok, bool isPtr=true)
Definition: checkother.cpp:357
void redundantAssignmentError(const Token *tok1, const Token *tok2, const std::string &var, bool inconclusive)
Definition: checkother.cpp:548
void checkVariableScope()
Check scope of variables
Definition: checkother.cpp:935
void unknownSignCharArrayIndexError(const Token *tok)
void checkInterlockedDecrement()
Check for race condition with non-interlocked access after InterlockedDecrement()
void clarifyCalculationError(const Token *tok, const std::string &op)
Definition: checkother.cpp:203
void signedCharArrayIndexError(const Token *tok)
void duplicateExpressionError(const Token *tok1, const Token *tok2, const Token *opTok, ErrorPath errors, bool hasMultipleExpr=false)
void warningOldStylePointerCast()
Are there C-style pointer casts in a c++ file?
Definition: checkother.cpp:295
void duplicateBranchError(const Token *tok1, const Token *tok2, ErrorPath errors)
void checkDuplicateExpression()
Check for suspicious code with the same expression on both sides of operator (e.g "if (a && a)")
void funcArgOrderDifferent(const std::string &functionName, const Token *declaration, const Token *definition, const std::vector< const Token * > &declarations, const std::vector< const Token * > &definitions)
void shadowError(const Token *var, const Token *shadowed, const std::string &type)
void funcArgNamesDifferent(const std::string &functionName, nonneg int index, const Token *declaration, const Token *definition)
void checkRedundantAssignment()
copying to memory or assigning to a variable twice
Definition: checkother.cpp:425
void unsignedPositiveError(const Token *tok, const ValueFlow::Value *v, const std::string &varname)
void checkCharVariable()
Using char variable as array index / as operand in bit operation.
void checkFuncArgNamesDifferent()
Check if function declaration and definition argument names different
void comparePointersError(const Token *tok, const ValueFlow::Value *v1, const ValueFlow::Value *v2)
void checkConstVariable()
void incompleteArrayFillError(const Token *tok, const std::string &buffer, const std::string &function, bool boolean)
void clarifyStatementError(const Token *tok)
Definition: checkother.cpp:251
CheckOther(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
This constructor is used when running checks.
Definition: checkother.h:66
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override
get error messages
Definition: checkother.h:293
void checkEvaluationOrder()
Check for expression that depends on order of evaluation of side effects
void unsignedLessThanZeroError(const Token *tok, const ValueFlow::Value *v, const std::string &varname)
void checkCastIntToCharAndBackError(const Token *tok, const std::string &strFunctionName)
Definition: checkother.cpp:134
void unusedLabelError(const Token *tok, bool inSwitch, bool hasIfdef)
void checkKnownArgument()
void constStatementError(const Token *tok, const std::string &type, bool inconclusive)
void checkModuloOfOneError(const Token *tok)
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override
Run checks against the normal token list.
Definition: checkother.h:71
void checkSuspiciousSemicolon()
Check for suspicious use of semicolon
Definition: checkother.cpp:261
void checkAccessOfMovedVariable()
Check for access of moved or forwarded variable
void varFuncNullUBError(const Token *tok)
void knownArgumentError(const Token *tok, const Token *ftok, const ValueFlow::Value *value, const std::string &varexpr, bool isVariableExpressionHidden)
void overlappingWriteUnion(const Token *tok)
void checkUnusedLabel()
Check for unused labels
void knownPointerToBoolError(const Token *tok, const ValueFlow::Value *value)
void checkConstPointer()
void pointerLessThanZeroError(const Token *tok, const ValueFlow::Value *v)
void pointerPositiveError(const Token *tok, const ValueFlow::Value *v)
void checkComparePointers()
void checkUnreachableCode()
Check for code that gets never executed, such as duplicate break statements
Definition: checkother.cpp:770
void redundantPointerOpError(const Token *tok, const std::string &varname, bool inconclusive, bool addressOfDeref)
void overlappingWriteFunction(const Token *tok)
void checkDuplicateBranch()
Check for suspicious code where if and else branch are the same (e.g "if (a) b = true; else b = true;...
void checkZeroDivision()
Check zero division
void selfAssignmentError(const Token *tok, const std::string &varname)
void oppositeExpressionError(const Token *opTok, ErrorPath errors)
void suspiciousCaseInSwitchError(const Token *tok, const std::string &operatorString)
Definition: checkother.cpp:757
void checkRedundantPointerOp()
Check for redundant pointer operations
void suspiciousSemicolonError(const Token *tok)
Definition: checkother.cpp:285
void checkIncompleteArrayFill()
Check for buffers that are filled incompletely with memset and similar functions
void duplicateBreakError(const Token *tok, bool inconclusive)
Definition: checkother.cpp:879
void zerodivError(const Token *tok, const ValueFlow::Value *value)
void checkComparisonFunctionIsAlwaysTrueOrFalseError(const Token *tok, const std::string &functionName, const std::string &varName, const bool result)
void invalidPointerCastError(const Token *tok, const std::string &from, const std::string &to, bool inconclusive, bool toIsInt)
Definition: checkother.cpp:412
std::string classInfo() const override
get information about this class, used to generate documentation
Definition: checkother.h:371
CheckOther()
This constructor is used when registering the CheckClass.
Definition: checkother.h:56
void checkShadowVariables()
Check for shadow variables.
void checkComparisonFunctionIsAlwaysTrueOrFalse()
Check for using of comparison functions evaluating always to true or false.
void checkRedundantCopy()
Check for code creating redundant copies
void checkNegativeBitwiseShift()
Check for bitwise shift with negative right operand
void unreachableCodeError(const Token *tok, const Token *noreturn, bool inconclusive)
Definition: checkother.cpp:887
void redundantInitializationError(const Token *tok1, const Token *tok2, const std::string &var, bool inconclusive)
Definition: checkother.cpp:562
void duplicateAssignExpressionError(const Token *tok1, const Token *tok2, bool inconclusive)
void checkSignOfUnsignedVariable()
Check for testing sign of unsigned variable
static std::string myName()
Definition: checkother.h:367
void checkPassByReference()
Check for function parameters that should be passed by reference
void charBitOpError(const Token *tok)
void misusedScopeObjectError(const Token *tok, const std::string &varname, bool isAssignment=false)
void passedByValueError(const Variable *var, bool inconclusive, bool isRangeBasedFor=false)
void checkSuspiciousCaseInSwitch()
Check for code like 'case A||B:'
Definition: checkother.cpp:723
void clarifyStatement()
Suspicious statement like '*A++;'.
Definition: checkother.cpp:225
void accessMovedError(const Token *tok, const std::string &varname, const ValueFlow::Value *value, bool inconclusive)
void checkCastIntToCharAndBack()
Check to avoid casting a return value to unsigned char and then back to integer type.
Definition: checkother.cpp:84
void checkCommaSeparatedReturn()
Check for comma separated statements in return
void checkNanInArithmeticExpression()
Check for NaN (not-a-number) in an arithmetic expression.
void invalidFreeError(const Token *tok, const std::string &allocation, bool inconclusive)
void checkKnownPointerToBool()
void checkOverlappingWrite()
void checkVarFuncNullUB()
Check that variadic function calls don't use NULL.
void duplicateValueTernaryError(const Token *tok)
void checkMisusedScopedObject()
Check for objects that are destroyed immediately
void nanInArithmeticExpressionError(const Token *tok)
void redundantAssignmentInSwitchError(const Token *tok1, const Token *tok2, const std::string &var)
Definition: checkother.cpp:571
void commaSeparatedReturnError(const Token *tok)
void raceAfterInterlockedDecrementError(const Token *tok)
void invalidPointerCast()
Check for pointer casts to a type with an incompatible binary data representation.
Definition: checkother.cpp:372
void variableScopeError(const Token *tok, const std::string &varname)
void negativeBitwiseShiftError(const Token *tok, int op)
void clarifyCalculation()
Clarify calculation for ".. a * b ? ..".
Definition: checkother.cpp:154
void constVariableError(const Variable *var, const Function *function)
void checkInvalidFree()
Check for free() operations on invalid memory locations
void redundantBitwiseOperationInSwitchError()
Check for redundant bitwise operation in switch statement
Definition: checkother.cpp:594
void checkIncompleteStatement()
Incomplete statement.
void duplicateExpressionTernaryError(const Token *tok, ErrorPath errors)
void redundantCopyError(const Token *tok1, const Token *tok2, const std::string &var)
Definition: checkother.cpp:540
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
Information about a member variable.
#define CPPCHECKLIB
Definition: config.h:35
#define nonneg
Definition: config.h:138
std::list< ErrorPathItem > ErrorPath
Definition: errortypes.h:130