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.

arrayIndexThenCheck

Code style
Informational

Access array beyond boundaries

asctimeCalled

Code style
Informational

Obsolete function 'std::asctime' called. It is recommended to use 'strftime' instead.

assignBoolToFloat

Safety
Informational

Boolean value assigned to floating point variable.

assignIfError

Error prone
Informational

Mismatching assignment and comparison

catchExceptionByValue

Code style
Informational

Exception should be caught by reference.

clarifyCalculation

Code style
Informational

Clarify calculation precedence for '+' and '?'.

clarifyCondition

Code style
Informational

Suspicious condition (bitwise operator + comparison)

class_X_Y

Error prone
Informational

Code not handled

comparisonError

Code style
Informational

Detect conditions that are always true

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.

constArgument

Code style
Informational

Argument 'false&&static\_cast<bool>(!!(desc.version()==100))' to function isTrue is always 0

constParameter

Design
Informational

Parameter can be declared with const

constParameterCallback

Design
Informational

Parameter can be declared with const.

constVariable

Code style
Informational

Detect variables that could be const

cstyleCast

Code style
Informational

C-style pointer casting

duplicateAssignExpression

Code style
Informational

Duplicate assign expression

duplicateBreak

Code style
Informational

Consecutive return

duplicateCondition

Code style
Informational

Detect duplicate conditions

duplicateConditionalAssign

Code style
Informational

Duplicate conditions

duplicateExpression

Code style
Informational

Duplicate expressions

duplicateExpressionTernary

Code style
Informational

Duplicate Ternary operator

duplicateValueTernary

Code style
Informational

Duplicate ternary value

exceptRethrowCopy

Best practice
Informational

Rethrowing exception in an exception

hidingInheritedPublic

Design
Informational

Virtual function is a public in a base class and became not-public in derived. It's violate a substitutability a principle in OOP.

knownArgument

Best practice
Informational

Argument value is always known, could use a const

knownConditionTrueFalse

Code style
Informational

Condition value is always known

knownEmptyContainer

Error prone
Informational

Container is always empty

knownEmptyContainerLoop

Performance
Informational

Iterating over a container that is always empty.

missingOverride

Code style
Informational

Function overrides a function in a base class but is not marked with a 'override' specifier.

moduloofone

Safety
Informational

Modulo of one is always equal to zero

multiCondition

Code style
Informational

Expression is always false because 'else if' condition matches previous condition

nanInArithmeticExpression

Best practice
Informational

Using NaN/Inf in a computation.

noConstructor

Code style
Informational

Class does not have a constructor although it has private member variables.

noExplicitConstructor

Code style
Informational

Class has a constructor with 1 argument that is not explicit.

operatorEq

Best practice
Informational

Invalid equal operator

operatorEqRetRefThis

Best practice
Informational

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

oppositeExpression

Code style
Informational

Opposite expression on both sides of expression

pointerLessThanZero

Safety
Informational

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

pointerPositive

Performance
Informational

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

redundantAssignment

Code style
Informational

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

redundantCondition

Code style
Informational

Redundant condition

redundantIfRemove

Safety
Informational

Redundant checking of STL container element existence before removing it.

redundantInitialization

Error prone
Informational

Redundant initialization. The initialized value is overwritten before it is read.

redundantPointerOp

Code style
Informational

Redundant pointer operation on 'CB' - it's already a pointer.

returnNonBoolInBooleanFunction

Safety
Informational

Non-boolean value returned from function returning bool

sameIteratorExpression

Best practice
Informational

Same iterators expression are used for algorithm.

shadowArgument

Design
Informational

Local variable shadows outer argument

shadowFunction

Code style
Informational

Local variable shadows outer function

shadowVar

Code style
Informational

Local variable shadows outer variable

shadowVariable

Design
Informational

Local variable shadows outer variable

templateRecursion

Design
Informational

Template recursion threshold reached

truncLongCastAssignment

Safety
Informational

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

truncLongCastReturn

Error prone
Informational

int result is returned as long value. If the return value is long to avoid loss of information

unassignedVariable

Code style
Informational

Detect variables that are not assigned (e.g. dead code)

unpreciseMathCall

Unknown
Informational

Expression can be replaced to avoid loss of precision.

unreachableCode

Code style
Informational

Statements following return ; dead code

unsafeClassCanLeak

Security
Informational

Class is unsafe

unsafeClassDivZero

Code style
Informational

Public interface is not safe.

unsignedLessThanZero

Code style
Informational

Checking if unsigned expression is less than zero.

unsignedPositive

Code style
Informational

Unsigned expression can't be negative so it is unnecessary to test it.

unusedAllocatedMemory

Code style
Informational

Variable is allocated memory that is never used.

unusedLabel

Code style
Informational

Label is not used.

unusedLabelConfiguration

Design
Informational

Label is not used, a pre-processor configuration prevents it to be shown.

unusedPrivateFunction

Code style
Informational

Unused private function

unusedScopedObject

Best practice
Informational

Instance of object is destroyed immediately.

unusedStructMember

Code style
Informational

struct member is never used.

unusedVariable

Code style
Informational

Unused variable

uselessAssignmentArg

Code style
Informational

Assignment of function parameter has no effect outside the function.

useStlAlgorithm

Code style
Informational

Consider using std::generate algorithm instead of a raw loop.

legacyUninitvar

Best practice
Informational

Uninitialized variable

nonStandardCharLiteral

Error prone
Informational

Non-standard character literal

We use cookies to improve your site experience, including analytics cookies to understand how you use our product and design better experiences. Please read our Cookie Policy.