Octal integer literal

ID

c.correctness.octal_constant

Severity

low

Remediation Complexity

trivial

Remediation Risk

medium

Remediation Effort

low

Resource

Numeric Literal

Language

C / C++

Description

This integer literal begins with a leading 0, so it is interpreted as octal (base 8), not decimal. A reader may misread 010 as ten when it is actually eight. If a decimal value was intended, drop the leading zero; if octal is intended, add a comment to make it explicit.

Rationale

This integer literal begins with a leading 0, so it is interpreted as octal (base 8), not decimal. A reader may misread 010 as ten when it is actually eight. If a decimal value was intended, drop the leading zero; if octal is intended, add a comment to make it explicit.

The following code illustrates the pattern detected by this rule:

int code;
// FLAGGED: Octal integer literal
code = 0777;
// FLAGGED: Octal integer literal
code = 010;

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.