Rule Definition
A switch statement with a single path is redundant and may be indicative of a programming error.
Remediation
If switch has only 1 case clause then maybe it is not needed. Review the logic.
Violation Code Sample
switch ( x )
{ default: /* Non-compliant - switch is redundant */
x = 0;
break;
}
switch ( y )
{ case 1:
default: /* Non-compliant - switch is redundant */
y = 0;
break;
}
Fixed Code Sample
switch ( z )
{
case 1:
z = 2;
break;
default: /* Compliant */
z = 0;
break;
}
Reference
MISRA C 2012, 16.6: Every switch statement shall have at least two switch-clauses
Related Technologies
Technical Criterion
Programming Practices - Structuredness
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.