Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 declaring using integer constants, for example, as in:

Code Block
bgColor#FFCCCC
i_array[0] = 2192719;
i_array[1] = 4435;
i_array[2] = 0420042;

The constant

Code Block

042

is interpreted as octal, with decimal value

Code Block

34

...

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 32.

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.

Code Block
bgColor#FFFFCC

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.

...