facebook pixelC and C++ Static Code Analysis Rules
BACK TO LIST

C / C++ rules

C and C++ are really performant languages and can be very error-prone. We all had core dumps and made pointer arithmetic errors! Thankfully, Codiga has hundreds of static analysis rules to flag potential errors in your C/C++ code, automate code reviews and merge with confidence.

      accessMoved

      Best practice
      High

      Access of moved variable.

      allocaCalled

      Best practice
      High

      Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead.

      arrayIndexOutOfBoundsCond

      Best practice
      High

      Array access out of bounds with a conditions

      asctime_sCalled

      Best practice
      High

      Obsolete function 'asctime_s' called. It is recommended to use 'strftime' instead.

      assertWithSideEffect

      Best practice
      High

      Assert statement calls a function which may have desired side effects: 'IsAddressInSegment'.

      assignmentInAssert

      Best practice
      High

      Assert statement modifies variable

      compareBoolExpressionWithInt

      Best practice
      High

      Comparison of a boolean expression with an integer other than 0 or 1.

      constStatement

      Best practice
      High

      Detect unused variables

      derefInvalidIteratorRedundantCheck

      Best practice
      High

      Condition is redundant or value is derefenced

      exceptThrowInDestructor

      Best practice
      High

      Catching exception in destructor

      funcArgOrderDifferent

      Best practice
      High

      Function not called with the right arguments

      getsCalled

      Best practice
      High

      Obsolute function gets() called

      identicalConditionAfterEarlyExit

      Best practice
      High

      Identical condition and return expression

      identicalInnerCondition

      Best practice
      High

      Identical inner 'return' condition is always true.

      ignoredReturnValue

      Best practice
      High

      Return value not used

      incorrectLogicOperator

      Best practice
      High

      Logical conjunction always evaluates to false

      integerOverflowCond

      Best practice
      High

      Integer overflow with condition

      invalidLengthModifierError

      Best practice
      High

      Format string conversion error

      invalidPrintfArgType_float

      Best practice
      High

      Invalid formatter for float

      invalidPrintfArgType_sint

      Best practice
      High

      Invalid formatter for signed long long

      invalidPrintfArgType_uint

      Best practice
      High

      Invalid formatter for unsigned int

      invalidscanf

      Best practice
      High

      Invalid scanf

      invalidScanfArgType_int

      Best practice
      High

      Invalid scanf for int

      invalidTestForOverflow

      Best practice
      High

      Invalid test for overflow

      literalWithCharPtrCompare

      Best practice
      High

      Direct string comparison. Compare with strcmp() instead

      mismatchingContainerExpression

      Best practice
      High

      Iterators to containers from different expressions

      negativeIndex

      Best practice
      High

      Negative index access

      noCopyConstructor

      Best practice
      High

      Class does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).

      noOperatorEq

      Best practice
      High

      Class does not have a operator= which is recommended since it has dynamic memory/resource allocation(s).

      nullPointerArithmeticRedundantCheck

      Best practice
      High

      Either the condition is redundant or there is overflow in pointer subtraction.

      nullPointerRedundantCheck

      Best practice
      High

      Either the condition is redundant or there is possible null pointer dereference

      objectIndex

      Best practice
      High

      The address of local variable might be accessed at non-zero index.

      operatorEqToSelf

      Best practice
      High

      operator=' should check for assignment to self to avoid problems with dynamic memory.

      operatorEqVarError

      Best practice
      High

      Member variable is not assigned a value

      oppositeInnerCondition

      Best practice
      High

      Opposite inner 'return' condition leads to a dead code block.

      pointerSize

      Best practice
      High

      Size of pointer used instead of size of its data.

      redundantAssignInSwitch

      Best practice
      High

      Variable is reassigned a value before the old one has been used

      seekOnAppendedFile

      Best practice
      High

      Repositioning operation performed on a file opened in append mode has no effect.

      selfAssignment

      Best practice
      High

      Redundant assignment of variable to itself.

      signConversion

      Best practice
      High

      Expression can have a negative value. That is converted to an unsigned value and used in an unsigned calculation.

      sizeofCalculation

      Best practice
      High

      Calculation inside sizeof().

      sizeofDivisionMemfunc

      Best practice
      High

      Division by result of sizeof(). memset() expects a size in bytes

      staticStringCompare

      Best practice
      High

      Unnecessary comparison of static strings.

      uninitMemberVar

      Best practice
      High

      Member variable not initialized in the constructor.

      uninitMemberVarPrivate

      Best practice
      High

      Member private variable is not initialized in the constructor.

      uselessAssignmentPtrArg

      Best practice
      High

      Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?

      uselessCallsEmpty

      Best practice
      High

      Ineffective call of function 'empty()'. Call 'clear()' instead.

      virtualCallInConstructor

      Best practice
      High

      Dynamic binding is not used.

      mismatchingBitAnd

      Best practice
      High

      Mismatching bitmasks.

      returnStdMoveLocal

      Best practice
      High

      Using std::move for returning object by-value from function will affect copy elision optimization

      Learn more