CertC-DCL18ΒΆ
Do not begin integer constants with 0 when specifying a decimal value
Required inputs: IR
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:
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:
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 | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
| DCL18-C | Low | Unlikely | Low | P3 | L3 |
Related Guidelines
| MISRA C:2012 | Rule 7.1 (required) |
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
octal_literal |
Use of octal literal. |
None |
False |
Options
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.