50     friend class TestCharVar;
 
   51     friend class TestIncompleteStatement;
 
   52     friend class TestOther;
 
   59     static bool comparisonNonZeroExpressionLessThanZero(
const Token *tok, 
const ValueFlow::Value *&zeroValue, 
const Token *&nonZeroExpr, 
bool suppress = 
false);
 
   62     static bool testIfNonZeroExpressionIsPositive(
const Token *tok, 
const ValueFlow::Value *&zeroValue, 
const Token *&nonZeroExpr);
 
   67         : 
Check(myName(), tokenizer, settings, errorLogger) {}
 
  119     void clarifyCalculation();
 
  122     void clarifyStatement();
 
  125     void warningOldStylePointerCast();
 
  128     void invalidPointerCast();
 
  131     void checkVariableScope();
 
  132     bool checkInnerScope(
const Token *tok, 
const Variable* var, 
bool& used) 
const;
 
  135     void checkCommaSeparatedReturn();
 
  138     void checkPassByReference();
 
  140     void checkConstVariable();
 
  141     void checkConstPointer();
 
  144     void checkCharVariable();
 
  147     void checkIncompleteStatement();
 
  150     void checkZeroDivision();
 
  153     void checkNanInArithmeticExpression();
 
  156     void checkRedundantAssignment();
 
  159     void redundantBitwiseOperationInSwitchError();
 
  162     void checkSuspiciousCaseInSwitch();
 
  165     void checkMisusedScopedObject();
 
  168     void checkDuplicateBranch();
 
  171     void checkDuplicateExpression();
 
  174     void checkUnreachableCode();
 
  177     void checkSignOfUnsignedVariable();
 
  180     void checkSuspiciousSemicolon();
 
  183     void checkInvalidFree();
 
  184     void invalidFreeError(
const Token *tok, 
const std::string &allocation, 
bool inconclusive);
 
  187     void checkRedundantCopy();
 
  190     void checkNegativeBitwiseShift();
 
  193     void checkIncompleteArrayFill();
 
  196     void checkVarFuncNullUB();
 
  199     void checkCastIntToCharAndBack();
 
  202     void checkComparisonFunctionIsAlwaysTrueOrFalse();
 
  205     void checkRedundantPointerOp();
 
  208     void checkInterlockedDecrement();
 
  211     void checkUnusedLabel();
 
  214     void checkEvaluationOrder();
 
  217     void checkAccessOfMovedVariable();
 
  220     void checkFuncArgNamesDifferent();
 
  223     void checkShadowVariables();
 
  225     void checkKnownArgument();
 
  227     void checkKnownPointerToBool();
 
  229     void checkComparePointers();
 
  231     void checkModuloOfOne();
 
  233     void checkOverlappingWrite();
 
  234     void overlappingWriteUnion(
const Token *tok);
 
  235     void overlappingWriteFunction(
const Token *tok);
 
  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);
 
  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);
 
  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);
 
  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);
 
  269     void redundantContinueError(
const Token* tok);
 
  270     void unsignedLessThanZeroError(
const Token *tok, 
const ValueFlow::Value *v, 
const std::string &varname);
 
  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);
 
  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);
 
  291     void checkModuloOfOneError(
const Token *tok);
 
  362         const std::vector<const Token *> nullvec;
 
  372         return "Other checks\n" 
  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" 
  386                "- either division by zero or useless condition\n" 
  387                "- access of moved or forwarded variable.\n" 
  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" 
  395                "- Passing NULL pointer to function with variable number of arguments leads to UB.\n" 
  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";
 
void unknownEvaluationOrder(const Token *tok)
 
void cstyleCastError(const Token *tok, bool isPtr=true)
 
void redundantAssignmentError(const Token *tok1, const Token *tok2, const std::string &var, bool inconclusive)
 
void checkVariableScope()
Check scope of variables
 
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)
 
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?
 
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
 
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)
 
CheckOther(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
This constructor is used when running checks.
 
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override
get error messages
 
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)
 
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.
 
void checkSuspiciousSemicolon()
Check for suspicious use of semicolon
 
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 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
 
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)
 
void checkRedundantPointerOp()
Check for redundant pointer operations
 
void suspiciousSemicolonError(const Token *tok)
 
void checkIncompleteArrayFill()
Check for buffers that are filled incompletely with memset and similar functions
 
void duplicateBreakError(const Token *tok, bool inconclusive)
 
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)
 
std::string classInfo() const override
get information about this class, used to generate documentation
 
CheckOther()
This constructor is used when registering the CheckClass.
 
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)
 
void redundantInitializationError(const Token *tok1, const Token *tok2, const std::string &var, bool inconclusive)
 
void duplicateAssignExpressionError(const Token *tok1, const Token *tok2, bool inconclusive)
 
void checkSignOfUnsignedVariable()
Check for testing sign of unsigned variable
 
static std::string myName()
 
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:'
 
void clarifyStatement()
Suspicious statement like '*A++;'.
 
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.
 
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)
 
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.
 
void variableScopeError(const Token *tok, const std::string &varname)
 
void negativeBitwiseShiftError(const Token *tok, int op)
 
void clarifyCalculation()
Clarify calculation for ".. a * b ? ..".
 
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
 
void checkIncompleteStatement()
Incomplete statement.
 
void duplicateExpressionTernaryError(const Token *tok, ErrorPath errors)
 
void redundantCopyError(const Token *tok1, const Token *tok2, const std::string &var)
 
Interface class that cppcheck uses to communicate with the checks.
 
This is an interface, which the class responsible of error logging should implement.
 
This is just a container for general settings so that we don't need to pass individual values to func...
 
The token list that the TokenList generates is a linked-list of this class.
 
The main purpose is to tokenize the source code.
 
const Settings & getSettings() const
 
Information about a member variable.
 
std::list< ErrorPathItem > ErrorPath