GitHub
CERT Secure Coding

DCL18-C. Do not begin integer constants with 0 when specifying a decimal value

The C Standard defines octal constants as a 0 followed by octal digits (0 1 2 3 4 5 6 7). Programming errors can occur when decimal values are mistakenly specified as octal constants.

Noncompliant Code Example

In this noncompliant code example, a decimal constant is mistakenly prefaced with zeros so that all the constants are a fixed length:

Non-compliant code
i_array[0] = 2719;
i_array[1] = 4435;
i_array[2] = 0042;

Although it may appear that i_array[2] is assigned the decimal value 42, it is actually assigned the decimal value 34.

Compliant Solution

To avoid using wrong values and to make the code more readable, do not preface constants with zeroes if the value is meant to be decimal:

Compliant code
i_array[0] = 2719;
i_array[1] = 4435;
i_array[2] =   42;

Risk Assessment

Misrepresenting decimal values as octal can lead to incorrect comparisons and assignments.

Rule Severity Likelihood Detectable Repairable Priority Level
DCL18-C Low Unlikely No No P1 L3

Automated Detection

Tool

Version

Checker

Description

Astrée25.10octal-constantFully checked
Axivion Bauhaus Suite7.2.0CertC-DCL18
CodeSonar9.1p0LANG.TYPE.OCOctal constant
Helix QAC2025.2C0339, C1272
Klocwork2025.2MISRA.TOKEN.OCTAL.ESCAPE
MISRA.TOKEN.OCTAL.INT

LDRA tool suite9.7.183 SFully Implemented
Parasoft C/C++test
2025.2

CERT_C-DCL18-a
CERT_C-DCL18-b

Octal and hexadecimal escape sequences shall be terminated
Octal constants (other than zero) shall not be used

PC-lint Plus

1.4

9001

Fully supported

Polyspace Bug Finder

R2025b

CERT C: Rec. DCL18-CChecks for use of octal constants (rec. fully covered)


PVS-Studio

7.42

V536
RuleChecker
25.10
octal-constantFully checked
SonarQube C/C++ Plugin
3.11
OctalConstantAndSequence
MISRA C:2012Rule 7.1 (required)