facebook pixelCodiga Analysis C / C++ Rules, severity error
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.

accessForwarded

Safety
Error

Access of forwarded variable

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.

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'.

assignmentInAssert

Best practice
Error

Assert statement modifies variable

badBitmaskCheck

Error prone
Error

Bad usage of bitmap operator

charLiteralWithCharPtrCompare

Safety
Error

Char literal compared with pointer.

checkCastIntToCharAndBack

Error prone
Error

Storing getchar() return value in char variable and then comparing with EOF.

clarifyStatement

Error prone
Error

Misuse of ++ operator

compareBoolExpressionWithInt

Best practice
Error

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

comparisonOfBoolWithInvalidComparator

Error prone
Error

Comparison of a boolean value using relational operator (e.g. < ,>, etc)

constStatement

Best practice
Error

Detect unused variables

containerOutOfBounds

Safety
Error

Access container out of bounds

copyCtorPointerCopying

Design
Error

Value of pointer 'count'

derefInvalidIteratorRedundantCheck

Best practice
Error

Condition is redundant or value is derefenced

duplInheritedMember

Design
Error

Duplicated inherited member

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

incorrectCharBooleanError

Error prone
Error

Conversion of char literal to bool always evaluates to true.

incorrectLogicOperator

Best practice
Error

Logical conjunction always evaluates to false

incorrectStringBooleanError

Error prone
Error

Incorrect string boolean operator

integerOverflowCond

Best practice
Error

Integer overflow with condition

invalidLengthModifierError

Best practice
Error

Format string conversion error

invalidPrintfArgType_float

Best practice
Error

Invalid formatter for float

invalidPrintfArgType_n

Safety
Error

Invalid formatter for int

invalidPrintfArgType_p

Safety
Error

Invalid formatter for signed int

invalidPrintfArgType_s

Safety
Error

Invalid formatter for string

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_float

Safety
Error

Invalid scanf for float

invalidScanfArgType_int

Best practice
Error

Invalid scanf for int

invalidScanfArgType_s

Safety
Error

Invalid scanf for string

invalidTestForOverflow

Best practice
Error

Invalid test for overflow

literalWithCharPtrCompare

Best practice
Error

Direct string comparison. Compare with strcmp() instead

localMutex

Safety
Error

The lock is ineffective because the mutex is locked at the same scope as the mutex itself.

memsetValueOutOfRange

Security
Error

Invalid memset assignment

memsetZeroBytes

Error prone
Error

memset() called to fill 0 bytes.

mismatchingContainerExpression

Best practice
Error

Iterators to containers from different expressions

negativeContainerIndex

Safety
Error

Negative container index

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).

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.

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.

pointerSize

Best practice
Error

Size of pointer used instead of size of its data.

publicAllocationError

Security
Error

Possible leak in public function.

redundantAssignInSwitch

Best practice
Error

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

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.

signConversion

Best practice
Error

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

signConversionCond

Security
Error

Conversion between unsigned and signed values

sizeofCalculation

Best practice
Error

Calculation inside sizeof().

sizeofDivisionMemfunc

Best practice
Error

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

sizeofFunctionCall

Error prone
Error

Found function call inside sizeof().

sizeofwithnumericparameter

Safety
Error

Suspicious usage of 'sizeof' with a numeric constant as parameter.

sizeofwithsilentarraypointer

Error prone
Error

Using 'sizeof' on array given as function argument returns size of a pointer.

staticStringCompare

Best practice
Error

Unnecessary comparison of static strings.

stlIfFind

Error prone
Error

Suspicious condition. The result of find() is an iterator

StlMissingComparison

Safety
Error

Missing bounds check for extra iterator increment in loop.

thisSubtraction

Safety
Error

Suspicious pointer subtraction.

uninitMemberVar

Best practice
Error

Member variable not initialized in the constructor.

uninitMemberVarPrivate

Best practice
Error

Member private variable is not initialized in the constructor.

unusedLabelSwitch

Design
Error

Label is not used.

unusedLabelSwitchConfiguration

Design
Error

Unused label in switch

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.

uselessCallsRemove

Error prone
Error

Return value ignored. Elements remain in container.

virtualCallInConstructor

Best practice
Error

Dynamic binding is not used.

wrongPrintfScanfParameterPositionError

Error prone
Error

printf: invalid parameter position

zerodivcond

Safety
Error

Either the condition is redundant or there is division by zero

pointerOutOfBoundsCond

Security
Error

Undefined behaviour, when 'len' is 4 the pointer arithmetic 'cmd+len' is out of bounds

mismatchingBitAnd

Best practice
Error

Mismatching bitmasks.

ctuOneDefinitionRuleViolation

Design
Error

The one definition rule is violated, different classes/structs have the same name.

uninitDerivedMemberVar

Safety
Error

Member variable not initialized in constructor

returnStdMoveLocal

Best practice
Error

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

Learn more

overlappingWriteUnion

Safety
Error

Overlapping read/write of union is undefined behavior

argumentSize

Security
Error

Buffer is too small

mismatchingContainers

Safety
Error

Iterators of different containers are used together.

operatorEqShouldBeLeftUnimplemented

Design
Error

operator should either return reference to 'this' instance or be declared private and left unimplemented.

va_start_wrongParameter

Error prone
Error

Wrong parameter for va_start()