The C ISO Standard defines octal constants as a 0 followed by octal digits (0 1 2 3 4 5 6 7).
This can lead to programming errors in constants that are meant to be taken by their decimal value, especially when declaring multiple constants and preserving fixed length.
Example
When declaring integer constants as in:
Code Block |
---|
i_array[0] = 219; i_array[1] = 042; |
The constant
Code Block |
---|
042 |
is interpreted as octal, with decimal value
Code Block |
---|
34 |
Which might or might not be what the programmer wanted.
Risk assesment
Misinterpreting decimal values as octal could lead to an incorrect value being written into code.
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
DCL18-C | low | unlikely | low | P3 | L3 |
References
Wiki Markup |
---|
\[[ISO/IEC 9899:1999|cplusplus:AA. C References#ISO/IEC 9899-1999]\] Section 6.4.4.1 "Integer constants" \[cplusplus:MISRA 04\] Section 6.7 Rule 7.1 |