Missing case for switch condition
switch
variable not covered by cases and default case is
missing
Description
This defect occurs
when the switch
variable can take values that are
not covered by a case
statement.
Note
Bug Finder only raises a defect if the switch variable is not full range.
Risk
If the switch
variable takes a value that is not covered by a
case
statement, your program can have unintended
behavior.
A switch-statement that makes a security decision is particularly vulnerable when all possible values are not explicitly handled. An attacker can use this situation to deviate the normal execution flow.
Fix
It is good practice to use a default
statement as a
catch-all for values that are not covered by a
case
statement. Even if the switch
variable takes an unintended value, the resulting behavior can be
anticipated.
Examples
Result Information
Group: Security |
Language: C | C++ |
Default: Off |
Command-Line Syntax: MISSING_SWITCH_CASE |
Impact: Low |
Version History
Introduced in R2015b
See Also
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)