Skip to content

Missing Default Case in Switch Statement

Description

The code does not have a default case in a switch statement, which can lead to unexpected behavior if an unhandled condition occurs.

Examples

Insecure Code

c
switch (x) { case 1: break; }

Secure Code

c
switch (x) { case 1: break; default: break; }

Remediation

Add a default case to the switch statement to handle unexpected conditions.

Rule Details

FieldValue
IDCODE-0512
CategoryGeneric
SeverityLOW
CWECWE-478
ConfidenceLOW
ImpactLOW
LikelihoodMEDIUM
ExploitabilityCOMPLEX
Tags
OWASPN/A

References