#This script is designed to run with Understand - CodeCheck use base ("Understand::Codecheck"); use strict; use constant ERR1 => 'Octal Constants not allowed: %1'; use constant ERR2 => 'Octal Escape Sequences not allowed: %1'; sub register_tr_text() { my $check = shift; $check->add_tr_text(ERR1); $check->add_tr_text(ERR2); } sub name { return "2-13-2 Octal constants and octal escape sequences shall not be used";} sub description { return "2-13-2 (Required) Octal constants (other than zero) and octal escape sequences(other than \"\\0\") shall not be used.";} sub detailed_description { return <<"END_DESC"
Rationale
Any integer constant beginning with a "0" (zero) is treated as octal. Because of this, it is possible
for a zero-prefxed constant that is intended to be a decimal number to be incorrectly entered as an
octal number, contrary to developer expectations.
Octal escape sequences can also be problematic because the inadvertent introduction of a decimal digit (i.e. "8" or "9") ends the octal escape and introduces another character. The integer constant zero (written as a single numeric digit), is strictly speaking an octal constant, but is a permitted exception to this rule. Additionally, "\\0" is the only permitted octal escape sequence.
Example
The following array initialization for 3-digit decimal bus messages would not behave as
expected:
code[ 1 ] = 109; // Compliant - decimal 109
code[ 2 ] = 100; // Compliant - decimal 100
code[ 3 ] = 052; // Non-compliant - equivalent to decimal 42
code[ 4 ] = 071; // Non-compliant - equivalent to decimal 57
The value of the frst expression in the following example is implementation-defned because
the character constant consists of two characters, "\\10" and "9". The second character constant
expression contains the single character "\\100".
code[ 5 ] = '\\109'; // Non-compliant - implementation-defined, two character constant
code[ 6 ] = '\\100'; // Non-compliant - set to 64.