Post · 1 min read· pp. 241–242

No Enumeration Ranges in Case Constructs (RPP02)

Level →\rightarrow Required

Category : Safety: : ✓\checkmark

code
Cyber:
:   ✓\checkmark

Goal : Maintainability: : ✓\checkmark

code
Reliability:
:   ✓\checkmark

Portability:
:   ✓\checkmark

Performance:

Security:

Remediation →\rightarrow Low

Verification Method →\rightarrow GNATcheck rule: Enumeration_Ranges_In_CASE_Statements (builtin rule)

Reference

Similar to RPP01

Description

A range of enumeration literals must not be used as a choice in a case statement or a case expression. This includes explicit ranges (A .. B), subtypes, and the 'Range attribute. Much like the use of others in case statement alternatives, the use of ranges makes it possible for a new enumeration value to be added but not handled with a specific alternative, when a specific alternative was intended.

Applicable Vulnerability within ISO TR 24772-2

  • 6.5 Enumerator issues [CCB]

Applicable Common Weakness Enumeration

N/A

Noncompliant Code Example

ada
   case Digit_T (C) is
      when '0' | '9' =>
         C := Character'Succ (C);
      when '1' .. '8' =>
         C := Character'Pred (C);
   end case;

Compliant Code Example

ada
   case Digit_T (C) is
      when '0' | '9' =>
         C := Character'Succ (C);
      when '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' =>
         C := Character'Pred (C);
   end case;

Notes

N/A