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

arrayIndexOutOfBounds

Safety
Critical

Array accessed out of bounds

assignBoolToFloat

Safety
Informational

Boolean value assigned to floating point variable.

autoVariables

Safety
Critical

Address of local auto-variable assigned to a function parameter.

autovarInvalidDeallocation

Safety
Critical

Deallocation of an global variable results in undefined behaviour.

bufferAccessOutOfBounds

Safety
Critical

Buffer is accessed out of bounds: Ltrans[temp].addr

CastAddressToIntegerAtReturn

Safety
Warning

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

charLiteralWithCharPtrCompare

Safety
Error

Char literal compared with pointer.

comparePointers

Safety
Critical

Subtracting pointers that point to different objects

containerOutOfBounds

Safety
Error

Access container out of bounds

containerOutOfBoundsIndexExpression

Safety
Critical

Out of bounds access of variable

ctuArrayIndex

Safety
Critical

Detect array access out of bounds

ctunullpointer

Safety
Critical

Null pointer dereference: base

ctuPointerArith

Safety
Critical

Pointer arithmetic overflow

ctuuninitvar

Safety
Critical

Using argument that is uninitialized

danglingLifetime

Safety
Critical

Non-local variable use pointer to local variable

danglingTemporaryLifetime

Safety
Critical

Using object to temporary.

danglingTempReference

Safety
Critical

Using reference to dangling temporary.

deallocret

Safety
Critical

Returning/dereferencing value after it is deallocated / released

deallocuse

Safety
Critical

Dereferencing variable after it is deallocated / released

doubleFree

Safety
Critical

Memory freed twice

floatConversionOverflow

Safety
Critical

Float conversation overflow

integerOverflow

Safety
Critical

Integer overflow

invalidContainerLoop

Safety
Critical

Calling 'erase' while iterating the container is invalid.

invalidFunctionArg

Safety
Critical

Invalid function argument

invalidFunctionArgStr

Safety
Critical

Invalid string argument

invalidLifetime

Safety
Critical

Invalid use of scope/variable lifetime

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

invalidScanfArgType_float

Safety
Error

Invalid scanf for float

invalidScanfArgType_s

Safety
Error

Invalid scanf for string

invalidScanfFormatWidth

Safety
Critical

scanf call overwrite the memory allocated for the string

iterators3

Safety
Critical

Same iterator is used with different scopes

localMutex

Safety
Error

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

memleak

Safety
Critical

Memory leak: table.array

memleakOnRealloc

Safety
Critical

Common realloc mistake: value nulled but not freed upon failure

memsetClassFloat

Safety
Warning

Using memset() on union which contains a floating point number.

moduloofone

Safety
Informational

Modulo of one is always equal to zero

negativeContainerIndex

Safety
Error

Negative container index

nullPointer

Safety
Critical

Possible null pointer dereference

nullPointerArithmetic

Safety
Critical

Overflow in pointer arithmetic

operatorEqMissingReturnStatement

Safety
Critical

No 'return' statement in non-void function causes undefined behavior.

pointerArithBool

Safety
Critical

Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.

pointerLessThanZero

Safety
Informational

A pointer can not be negative so it is either pointless or an error to check if it is.

readWriteOnlyFile

Safety
Critical

Read operation on a file that was opened only for writing.

redundantIfRemove

Safety
Informational

Redundant checking of STL container element existence before removing it.

resourceLeak

Safety
Critical

Resource leak

returnDanglingLifetime

Safety
Critical

Returning pointer to local variable that will be invalid when returning.

returnNonBoolInBooleanFunction

Safety
Informational

Non-boolean value returned from function returning bool

returnReference

Safety
Critical

Reference to local variable returned.

shiftNegative

Safety
Critical

Shifting by a negative value is undefined behaviour

shiftTooManyBits

Safety
Critical

Shifting 64-bit value by 64 bits is undefined behaviour.

shiftTooManyBitsSigned

Safety
Critical

Shifting signed 32-bit value by 31 bits is implementation-defined behaviour.

sizeofwithnumericparameter

Safety
Error

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

sprintfOverlappingData

Safety
Critical

Undefined behavior: Variable is used as parameter and destination in sprintf().

stlcstr

Safety
Critical

Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.

StlMissingComparison

Safety
Error

Missing bounds check for extra iterator increment in loop.

stlOutOfBounds

Safety
Critical

Out of bounds acess to a container

strPlusChar

Safety
Critical

Unusual pointer arithmetic.

thisSubtraction

Safety
Error

Suspicious pointer subtraction.

throwInNoexceptFunction

Safety
Critical

Exception thrown in function declared not to throw exceptions.

truncLongCastAssignment

Safety
Informational

int result is assigned to long variable. If the variable is long to avoid loss of information

uninitvar

Safety
Critical

Uninitialized variable

useClosedFile

Safety
Critical

Used file that is not opened.

va_end_missing

Safety
Critical

va\_list 'argument\_list' was opened but not closed by va\_end().

va_list_usedBeforeStarted

Safety
Critical

va\_list 'cpy' used before va\_start() was called.

va_start_subsequentCalls

Safety
Critical

va\_start() or va\_copy() called subsequently on 'argptr' without va\_end() in between.

wrongPrintfScanfArgNum

Safety
Critical

mismatch printf parameters

zerodiv

Safety
Critical

Division by zero.

zerodivcond

Safety
Error

Either the condition is redundant or there is division by zero

uninitDerivedMemberVar

Safety
Error

Member variable not initialized in constructor

missingReturn

Safety
Critical

Missing return statement

overlappingWriteUnion

Safety
Error

Overlapping read/write of union is undefined behavior

mismatchingContainers

Safety
Error

Iterators of different containers are used together.