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:

// Adapted from MISRA C:2012 Rule 7.1 examples (octal constants).
void f(void)
{
    int code;
    // FLAGGED: Octal integer literal
    code = 0777;
    // FLAGGED: Octal integer literal
    code = 010;

    code = 0;
    code = 7777;
    (void)code;
}

Remediation

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

Configuration

This detector does not need any configuration.

References

© 2026 Xygeni. All rights reserved