facebook pixelCodiga Analysis C / C++ Rules, category best practice
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
Error

Access of moved variable.

allocaCalled

Best practice
Error

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

arithOperationsOnVoidPointer

Best practice
Warning

Avoid arithmetic operation on void pointers

arrayIndexOutOfBoundsCond

Best practice
Error

Array access out of bounds with a conditions

asctime_sCalled

Best practice
Error

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

assertWithSideEffect

Best practice
Error

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

AssignmentAddressToInteger

Best practice
Warning

Assigning a pointer to an integer is not portable.

assignmentInAssert

Best practice
Error

Assert statement modifies variable

CastIntegerToAddressAtReturn

Best practice
Warning

Returning an integer in a function with pointer return type is not portable.

compareBoolExpressionWithInt

Best practice
Error

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

ConfigurationNotChecked

Best practice
Informational

Skipping configuration 'RLIMIT\_AS;RLIMIT\_CPU;RLIMIT\_DATA;RLIMIT\_NPROC;RLIMIT\_VMEM' since the value of 'RLIMIT\_NPROC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

constStatement

Best practice
Error

Detect unused variables

derefInvalidIteratorRedundantCheck

Best practice
Error

Condition is redundant or value is derefenced

exceptRethrowCopy

Best practice
Informational

Rethrowing exception in an exception

exceptThrowInDestructor

Best practice
Error

Catching exception in destructor

funcArgOrderDifferent

Best practice
Error

Function not called with the right arguments

getsCalled

Best practice
Error

Obsolute function gets() called

identicalConditionAfterEarlyExit

Best practice
Error

Identical condition and return expression

identicalInnerCondition

Best practice
Error

Identical inner 'return' condition is always true.

ignoredReturnValue

Best practice
Error

Return value not used

incorrectLogicOperator

Best practice
Error

Logical conjunction always evaluates to false

integerOverflowCond

Best practice
Error

Integer overflow with condition

invalidLengthModifierError

Best practice
Error

Format string conversion error

invalidPointerCast

Best practice
Warning

Invalid pointer cast

invalidPrintfArgType_float

Best practice
Error

Invalid formatter for float

invalidPrintfArgType_sint

Best practice
Error

Invalid formatter for signed long long

invalidPrintfArgType_uint

Best practice
Error

Invalid formatter for unsigned int

invalidscanf

Best practice
Error

Invalid scanf

invalidScanfArgType_int

Best practice
Error

Invalid scanf for int

invalidTestForOverflow

Best practice
Error

Invalid test for overflow

knownArgument

Best practice
Informational

Argument value is always known, could use a const

leakNoVarFunctionCall

Best practice
Critical

Allocation failed

leakReturnValNotUsed

Best practice
Critical

return value of function not stored

literalWithCharPtrCompare

Best practice
Error

Direct string comparison. Compare with strcmp() instead

mismatchingContainerExpression

Best practice
Error

Iterators to containers from different expressions

nanInArithmeticExpression

Best practice
Informational

Using NaN/Inf in a computation.

negativeIndex

Best practice
Error

Negative index access

noCopyConstructor

Best practice
Error

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

noDestructor

Best practice
Warning

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

noOperatorEq

Best practice
Error

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

nullPointerArithmeticRedundantCheck

Best practice
Error

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

nullPointerRedundantCheck

Best practice
Error

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

objectIndex

Best practice
Error

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

operatorEq

Best practice
Informational

Invalid equal operator

operatorEqRetRefThis

Best practice
Informational

operator=' should return reference to 'this' instance.

operatorEqToSelf

Best practice
Error

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

operatorEqVarError

Best practice
Error

Member variable is not assigned a value

oppositeInnerCondition

Best practice
Error

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

pointerOutOfBounds

Best practice
Warning

Undefined behaviour

pointerSize

Best practice
Error

Size of pointer used instead of size of its data.

redundantAssignInSwitch

Best practice
Error

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

sameIteratorExpression

Best practice
Informational

Same iterators expression are used for algorithm.

seekOnAppendedFile

Best practice
Error

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

selfAssignment

Best practice
Error

Redundant assignment of variable to itself.

shiftNegativeLHS

Best practice
Warning

Shifting a negative value is technically undefined behaviour

signConversion

Best practice
Error

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

sizeofCalculation

Best practice
Error

Calculation inside sizeof().

sizeofDivisionMemfunc

Best practice
Error

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

staticStringCompare

Best practice
Error

Unnecessary comparison of static strings.

uninitMemberVar

Best practice
Error

Member variable not initialized in the constructor.

uninitMemberVarPrivate

Best practice
Error

Member private variable is not initialized in the constructor.

unusedScopedObject

Best practice
Informational

Instance of object is destroyed immediately.

uselessAssignmentPtrArg

Best practice
Error

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

uselessCallsEmpty

Best practice
Error

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

varFuncNullUB

Best practice
Warning

Passing NULL after the last typed argument to a variadic function leads to undefined behaviour.

virtualCallInConstructor

Best practice
Error

Dynamic binding is not used.

mismatchingBitAnd

Best practice
Error

Mismatching bitmasks.

legacyUninitvar

Best practice
Informational

Uninitialized variable

returnStdMoveLocal

Best practice
Error

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

Learn more