Limited Use of "others" in Aggregates (RPP03)

Level \(\rightarrow\) Advisory

Category
Safety:

\(\checkmark\)

Cyber:

\(\checkmark\)

Goal
Maintainability:

\(\checkmark\)

Reliability:

\(\checkmark\)

Portability:

\(\checkmark\)

Performance:

Security:

Remediation \(\rightarrow\) Low

Verification Method \(\rightarrow\) GNATcheck rule: OTHERS_In_Aggregates

Reference

Similar to RPP01

Description

Do not use an others choice in an extension aggregate. In record and array aggregates, do not use an others choice unless it is used either to refer to all components, or to all but one component.

This guideline prevents accidental provision of a general value for a record component or array component, when a specific value was intended. This possibility includes the case in which new components are added to an existing composite type.

Applicable Vulnerability within ISO TR 24772-2

  • 6.5 Enumerator issues [CCB]

  • 6.27 Switch statements and static analysis [CLL]

Applicable Common Weakness Enumeration

Noncompliant Code Example

   type Record_T is record
      Field1 : Integer   := 1;
      Field2 : Boolean   := False;
      Field3 : Character := ' ';
   end record;
   type Array_T is array (Character) of Boolean;
   Rec : Record_T := (Field1 => 1,
                      Field3 => '2',
                      others => <>);
   Arr : Array_T := ('0' .. '9' => True,
                     others     => False);

Compliant Code Example

   type Record_T is record
      Field1 : Integer   := 1;
      Field2 : Boolean   := False;
      Field3 : Character := ' ';
   end record;
   type Array_T is array (Character) of Boolean;
   Rec : Record_T := (Field1 => 1,
                      others => <>);
   Arr : Array_T := (others => False);

Notes

N/A