Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

A switch statement consists of several case labels, plus a default label. The default label is optional , but recommended. (see See guideline MSC01-C. Strive for logical completeness.) . A series of statements following a case label conventionally ends with a break; statement; if omitted, control flow falls through to the next case in the switch statement block. Because the break statement is not required, omitting it does not produce compiler diagnostics. If the omission was unintentional, this can result in an unexpected control flow.

...

A break statement is not required following the default case because it would not effect the control flow.

Exceptions

MSC17:-EX1: The last label in a switch statement requires no final break. This will conventionally be the default label.

MSC17:-EX2: When control flow is intended to cross statement labels, it is permissible to omit the break statement. In these instances, the unusual control flow must be explicitly documented.

...

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

MSC17-C

medium

likely

low

P6

L2

Automated Detection

Tool

Version

Checker

Description

Section

Compass/ROSE

...

 

 

 

Section

Coverity Prevent

Include Page
c:Coverity_V
c:Coverity_V
Section

MISSING_BREAK

Section

can find instances of missing break statement between cases in switch statement

...

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Other Languages

Related Guidelines

This rule appears in the C++ Secure Coding Standard as : MSC18-CPP. Finish every set of statements associated with a case label with a break statement.

Bibliography

...

MSC16-C. Consider encrypting function pointers      49. Miscellaneous (MSC)