You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

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.

Noncompliant code example

When using integer constants, for example, as in:

i_array[0] = 2719;
i_array[1] = 4435;
i_array[2] = 0042;

It seems as if the element in i_array is meant to hold the decimal value 42 instead of what actually gets stored, which is the value 34.

Compliant code example

To avoid using wrong values and make the code more readable, don't pad with zeroes if the value is meant to be decimal.

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

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

[[ISO/IEC 9899:1999]] Section 6.4.4.1 "Integer constants"
[MISRA 04] Section 6.7 Rule 7.1

  • No labels