Versions Compared

Key

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

...

Wiki Markup
*MSC09-EX0*: The {{break}} statement at the end of the final case in a {{switch}} statement may be omitted.  By convention, this is the {{default}} label. The {{break}} statement serves to transfer control to the end of the {{switch}} block.  Fall-through behavior also causes control to arrive at the end of the {{switch}} block. Consequently, control transfers to the statements following the {{switch}} block without regard to the presence or absence of the {{break}} statement.  Nevertheless, the final case in a {{switch}} statement should end with a {{break}} statement, in accordance with good programming style (see \[java:[Rogue 2000|AA. Bibliography#RogueReferences#Rogue 00]\]).

MSC09-EX1: When multiple cases require execution of identical code, then break statements may be omitted from all cases except the last one. For example:

...

CERT C Secure Coding Standard

MSC17-C. Finish every set of statements associated with a case label with a break statement

CERT C++ Secure Coding Standard

MSC18-CPP. Finish every set of statements associated with a case label with a break statement

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="64dba81a3f7b9413-f96bc247-42214076-8e7baa20-afb5dd7313ebed8c4f4b3a2b"><ac:plain-text-body><![CDATA[

[ISO/IEC TR 24772:2010

http://www.aitcnet.org/isai/]

"Switch Statements and Static Analysis [java:CLL]"

]]></ac:plain-text-body></ac:structured-macro>

MITRE CWE

CWE-484, "Omitted Break Statement in Switch"

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2890954421614de3-99fc06ce-4ee347b0-9e21914e-8b81d2abb936955fc3afc684"><ac:plain-text-body><![CDATA[

[java:[JLS 2005

AA. Bibliography#JLS References#JLS 05]]

[Section 14.11 The switch Statement

http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.11]

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="547c12d9f7a6f54b-68d69f9b-4d5649de-bf7784ae-667a10084e462984e1b35c8e"><ac:plain-text-body><![CDATA[

[java:[Rogue 2000

AA. Bibliography#Rogue References#Rogue 00]]

[The Elements of Java Style

http://www.ambysoft.com/books/elementsJavaStyle.html], Rule 78.

]]></ac:plain-text-body></ac:structured-macro>

...