RuleDescriptionKPI
arrayIndexThenCheckDefensive 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
assignBoolToFloatBoolean value assigned to floating point variable.Maintainability
assignIfErrorMismatching assignment and comparison comparison ” is always false.Maintainability
bitwiseOnBooleanBoolean variable ‘varname’ is used in bitwise operation. Did you mean ‘&&’?Maintainability
catchExceptionByValueThe exception is caught by value. It could be caught as a (const) reference which is usually recommended in C++.Robustness
clarifyCalculationSuspicious 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
clarifyConditionSuspicious condition (assignment + comparison); Clarify expression with parentheses.Maintainability
commaSeparatedReturnComma 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
comparisonErrorThe 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
comparisonOfBoolWithBoolErrorThe variable ‘var_name’ is of type ‘bool’ and comparing ‘bool’ value using relational (< > <= or >=) operator could cause unexpected results.Maintainability
comparisonOfFuncReturningBoolErrorThe 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
comparisonOfTwoFuncsReturningBoolErrorThe 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
copyCtorPointerCopyingValue of pointer ‘var’ which points to allocated memory is copied in copy constructor instead of allocating new memory.Maintainability
cstyleCastC-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
duplicateBranchFinding 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
duplicateBreakConsecutive return break continue goto or throw statements are unnecessary. The second statement can never be executed and so should be removed.Maintainability
duplicateExpressionFinding 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
duplicateExpressionTernaryFinding the same expression in both branches of ternary operator is suspicious as the same code is executed regardless of the condition.Maintainability
exceptRethrowCopyRethrowing 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
funcArgNamesDifferentFunction ‘function’ argument 2 names different: declaration ‘A’ definition ‘B’.Understandability
functionConstThe 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
incrementbooleanThe 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
initializerListMember 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
knownConditionTrueFalseCondition ‘x’ is always trueUnderstandability
mismatchingBitAndMismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0).Understandability
multiConditionExpression is always false because ‘else if’ condition matches previous condition at line 1.Understandability
nanInArithmeticExpressionUsing NaN/Inf in a computation. Although nothing bad really happens it is suspicious.Maintainability
noConstructorThe 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
noCopyConstructorclass ‘class’ does not have a copy constructor which is recommended since the class contains a pointer to allocated memory.Robustness
noExplicitConstructorClass ‘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
operatorEqThe 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
operatorEqShouldBeLeftUnimplementedoperator=’ should either return reference to ‘this’ instance or be declared private and left unimplemented.Accuracy
pointerLessThanZeroA pointer cannot be negative so it is either pointless or an error to check if it is.Maintainability
pointerPositiveA pointer cannot be negative so it is either pointless or an error to check if it is not.Maintainability
reademptycontainerReading from empty STL container ‘var’Understandability
redundantAssignmentVariable ‘var’ is reassigned a value before the old one has been used.Maintainability
redundantConditionRedundant condition: If x > 11 the condition x > 10 is always true.Maintainability
redundantIfRemoveRedundant checking of STL container element existence before removing it. It is safe to call the remove method on a non-existing element.Maintainability
redundantPointerOpRedundant pointer operation on ‘varname’ – it’s already a pointer.Maintainability
truncLongCastAssignmentint 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
truncLongCastReturnint 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
unassignedVariableVariable ‘varname’ is not assigned a value.Maintainability
unhandledExceptionSpecificationUnhandled exception specification when calling function foo(). Either use a try/catch around the function call or add a exception specification for funcname() also.Maintainability
unpreciseMathCallExpression ‘1 – erf(x)’ can be replaced by ‘erfc(x)’ to avoid loss of precision.Maintainability
unreachableCodeStatements following return break continue goto or throw will never be executed.Maintainability
unreadVariableVariable ‘varname’ is assigned a value that is never used.Understandability
unsafeClassCanLeakThe 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
unsignedLessThanZeroThe unsigned variable ‘varname’ will never be negative so it is either pointless or an error to check if it is.Maintainability
unsignedPositiveUnsigned variable ‘varname’ can’t be negative so it is unnecessary to test it.Maintainability
unusedAllocatedMemoryVariable ‘varname’ is allocated memory that is never used.Resource Utilization
unusedFunctionThe function ‘funcName’ is never used.Understandability
unusedLabelLabel ” is not used.Understandability
unusedPrivateFunctionUnused private function: ‘classname::funcname’Understandability
unusedScopedObjectInstance of ‘varname’ object is destroyed immediately.Understandability
unusedStructMemberstruct member ‘structname::variable’ is never used.Understandability
unusedVariableUnused variable: varnameUnderstandability
uselessAssignmentArgAssignment of function parameter has no effect outside the function.Understandability
variableScopeThe 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