arrayIndexThenCheck | Defensive programming: The variable ‘index’ is used as an array index before it is checked that is within limits. This can mean that the array might be accessed out of bounds. Reorder conditions such as ‘(a[i] && i < 10)' to '(i < 10 && a[i])'. That way the array will not be accessed if the index is out of limits. | Maintainability |
assignBoolToFloat | Boolean value assigned to floating point variable. | Maintainability |
assignIfError | Mismatching assignment and comparison comparison ” is always false. | Maintainability |
bitwiseOnBoolean | Boolean variable ‘varname’ is used in bitwise operation. Did you mean ‘&&’? | Maintainability |
catchExceptionByValue | The exception is caught by value. It could be caught as a (const) reference which is usually recommended in C++. | Robustness |
clarifyCalculation | Suspicious calculation. Please use parentheses to clarify the code. The code ”a+b?c:d” should be written as either ”(a+b)?c:d” or ”a+(b?c:d)”. | Maintainability |
clarifyCondition | Suspicious condition (assignment + comparison); Clarify expression with parentheses. | Maintainability |
commaSeparatedReturn | Comma is used in return statement. When comma is used in a return statement it can easily be misread as a semicolon. For example in the code below the value of ‘b’ is returned if the condition is true but it is easy to think that ‘a+1’ is returned:12 if (x)12 return a + 112 b++;12However it can be useful to use comma in macros. Cppcheck does not warn when such a macro is then used in a return statement it is less likely such code is misunderstood. | Maintainability |
comparisonError | The expression ‘(X & 0x6) == 0x1’ is always false. Check carefully constants and operators used these errors might be hard to spot sometimes. In case of complex expression it might help to split it to separate expressions. | Maintainability |
comparisonOfBoolWithBoolError | The variable ‘var_name’ is of type ‘bool’ and comparing ‘bool’ value using relational (< > <= or >=) operator could cause unexpected results. | Maintainability |
comparisonOfFuncReturningBoolError | The return type of function ‘func_name’ is ‘bool’ and result is of type ‘bool’. Comparing ‘bool’ value using relational (< > <= or >=) operator could cause unexpected results. | Maintainability |
comparisonOfTwoFuncsReturningBoolError | The return type of function ‘func_name1’ and function ‘func_name2’ is ‘bool’ and result is of type ‘bool’. Comparing ‘bool’ value using relational (< > <= or >=) operator could cause unexpected results. | Maintainability |
copyCtorPointerCopying | Value of pointer ‘var’ which points to allocated memory is copied in copy constructor instead of allocating new memory. | Maintainability |
cstyleCast | C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast const_cast dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically thus it is considered safer if the programmer explicitly states which kind of cast is expected. See also: https://www.securecoding.cert.org/confluence/display/cplusplus/EXP05-CPP.+Do+not+use+C-style+casts. | Maintainability |
duplicateBranch | Finding the same code in an ‘if’ and related ‘else’ branch is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct. | Maintainability |
duplicateBreak | Consecutive return break continue goto or throw statements are unnecessary. The second statement can never be executed and so should be removed. | Maintainability |
duplicateExpression | Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct. | Maintainability |
duplicateExpressionTernary | Finding the same expression in both branches of ternary operator is suspicious as the same code is executed regardless of the condition. | Maintainability |
exceptRethrowCopy | Rethrowing an exception with ‘throw varname;’ creates an unnecessary copy of ‘varname’. To rethrow the caught exception without unnecessary copying or slicing use a bare ‘throw;’. | Understandability |
funcArgNamesDifferent | Function ‘function’ argument 2 names different: declaration ‘A’ definition ‘B’. | Understandability |
functionConst | The member function ‘class::function’ can be made a const function. Making this function ‘const’ should not cause compiler errors. Even though the function can be made const function technically it may not make sense conceptually. Think about your design and the task of the function first – is it a function that must not change object internal state? | Maintainability |
incrementboolean | The operand of a postfix increment operator may be of type bool but it is deprecated by C++ Standard (Annex D-1) and the operand is always set to true. You should assign it the value ‘true’ instead. | Maintainability |
initializerList | Member variable ‘class::variable’ is in the wrong place in the initializer list. Members are initialized in the order they are declared not in the order they are in the initializer list. Keeping the initializer list in the same order that the members were declared prevents order dependent initialization errors. | Maintainability |
knownConditionTrueFalse | Condition ‘x’ is always true | Understandability |
mismatchingBitAnd | Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). | Understandability |
multiCondition | Expression is always false because ‘else if’ condition matches previous condition at line 1. | Understandability |
nanInArithmeticExpression | Using NaN/Inf in a computation. Although nothing bad really happens it is suspicious. | Maintainability |
noConstructor | The class ‘classname’ does not have a constructor although it has private member variables. Member variables of builtin types are left uninitialized when the class is instantiated. That may cause bugs or undefined behavior. | Maintainability |
noCopyConstructor | class ‘class’ does not have a copy constructor which is recommended since the class contains a pointer to allocated memory. | Robustness |
noExplicitConstructor | Class ‘classname’ has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided. | Maintainability |
operatorEq | The class::operator= does not conform to standard C/C++ behaviour. To conform to standard C/C++ behaviour return a reference to self (such as: ‘class &class::operator=(..) { .. return *this; }’. For safety reasons it might be better to not fix this message. If you think that safety is always more important than conformance then please ignore/suppress this message. For more details about this topic see the book Effective C++” by Scott Meyers.” | Robustness |
operatorEqRetRefThis | ‘operator=’ should return reference to ‘this’ instance. | Accuracy |
operatorEqShouldBeLeftUnimplemented | operator=’ should either return reference to ‘this’ instance or be declared private and left unimplemented. | Accuracy |
pointerLessThanZero | A pointer cannot be negative so it is either pointless or an error to check if it is. | Maintainability |
pointerPositive | A pointer cannot be negative so it is either pointless or an error to check if it is not. | Maintainability |
reademptycontainer | Reading from empty STL container ‘var’ | Understandability |
redundantAssignment | Variable ‘var’ is reassigned a value before the old one has been used. | Maintainability |
redundantCondition | Redundant condition: If x > 11 the condition x > 10 is always true. | Maintainability |
redundantIfRemove | Redundant checking of STL container element existence before removing it. It is safe to call the remove method on a non-existing element. | Maintainability |
redundantPointerOp | Redundant pointer operation on ‘varname’ – it’s already a pointer. | Maintainability |
truncLongCastAssignment | int result is assigned to long variable. If the variable is long to avoid loss of information then there is loss of information. To avoid loss of information you must cast a calculation operand to long for example ‘l = a * b;’ => ‘l = (long)a * b;’. | Robustness |
truncLongCastReturn | int result is returned as long value. If the return value is long to avoid loss of information then there is loss of information. To avoid loss of information you must cast a calculation operand to long for example ‘return a*b;’ => ‘return (long)a*b’. | Robustness |
unassignedVariable | Variable ‘varname’ is not assigned a value. | Maintainability |
unhandledExceptionSpecification | Unhandled exception specification when calling function foo(). Either use a try/catch around the function call or add a exception specification for funcname() also. | Maintainability |
unpreciseMathCall | Expression ‘1 – erf(x)’ can be replaced by ‘erfc(x)’ to avoid loss of precision. | Maintainability |
unreachableCode | Statements following return break continue goto or throw will never be executed. | Maintainability |
unreadVariable | Variable ‘varname’ is assigned a value that is never used. | Understandability |
unsafeClassCanLeak | The class ‘class’ is unsafe wrong usage can cause memory/resource leaks for ‘class::varname’. This can for instance be fixed by adding proper cleanup in the destructor. | Resource Utilization |
unsignedLessThanZero | The unsigned variable ‘varname’ will never be negative so it is either pointless or an error to check if it is. | Maintainability |
unsignedPositive | Unsigned variable ‘varname’ can’t be negative so it is unnecessary to test it. | Maintainability |
unusedAllocatedMemory | Variable ‘varname’ is allocated memory that is never used. | Resource Utilization |
unusedFunction | The function ‘funcName’ is never used. | Understandability |
unusedLabel | Label ” is not used. | Understandability |
unusedPrivateFunction | Unused private function: ‘classname::funcname’ | Understandability |
unusedScopedObject | Instance of ‘varname’ object is destroyed immediately. | Understandability |
unusedStructMember | struct member ‘structname::variable’ is never used. | Understandability |
unusedVariable | Unused variable: varname | Understandability |
uselessAssignmentArg | Assignment of function parameter has no effect outside the function. | Understandability |
variableScope | The scope of the variable ‘varname’ can be reduced. Warning: Be careful when fixing this message especially when there are inner loops. Here is an example where cppcheck will write that the scope for ‘i’ can be reduced:12void f(int x)12{12 int i = 0;12 if (x) {12 // it’s safe to move ‘int i = 0;’ here12 for (int n = 0; n < 10; ++n) {12 // it is possible but not safe to move 'int i = 0;' here12 do_something(&i);12 }12 }12}12When you see this message it is always safe to reduce the variable scope 1 level. | Maintainability |