Versions Compared

Key

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

...

However, the standard does not disallow jumping via goto or switch into loops that do not involve variably modified type identifiers. Consequently, loops and other blocks can be freely intermixed with switch statements. Unfortunately, this creates code that is, at best, confusing and unclear in what it does, which may can cause undesirable behavior.

The examples here fall under the exception MSC17-EX2 in recommendation MSC17-C. Finish every set of statements associated with a case label with a break statement.

...

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

MSC20-C

medium

probable

medium

P8

L2

Related Guidelines

CERT C++ Secure Coding Standard: MSC20-CPP. Do not use a switch statement to transfer control into a complex block

Bibliography

Wiki Markup\[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 6.8.6.1 "The goto statement" [MISRA 2004|AA. Bibliography#ISO/MISRA 04] Rule

MISRA Rule 15.1 [
Tom Duff on Duff's Device|http://www.lysator.liu.se/c/duffs-device.html]Device

Bibliography

...

      49. Miscellaneous (MSC)      MSC21-C. Use inequality to terminate a for loop