Versions Compared

Key

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

...

This noncompliant code example fails to test for conditions where in which a is neither b nor c. This may be the correct behavior in this case, but failure to account for all the values of a can result in logic errors if a unexpectedly assumes a different value.

...

Even though x is supposed to represent a bit (0 or 1) in the following code below, some error may have allowed x to assume a different value.
Detecting and dealing with that inconsistent state now rather than later will make the error easier to find and may prevent security violations.

...

Compliant Solution (Switch)

The compliant following ompliant solution below takes care to provide the default label to handle all valid values of type int:

...

ISO/IEC TR 24772 "CLL Switch statements Statements and static analysisStatic Analysis"

Bibliography

Wiki Markup
\[java:[Hatton 1995|AA. References#Hatton 95]\] Section 2.7.2, "Errors of omissionOmission and additionAddition"
\[java:[Viega 2005|AA. References#Viega 05]\] Section 5.2.17, "Failure to accountAccount for defaultDefault caseCase in switchSwitch"
\[[http://www.aeroxp.org/2009/01/lesson-on-infinite-loops]\] for analysis on the Zune 30 bug

...

MSC60-J. Detect and remove unused values       49. Miscellaneous (MSC)