Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added Rose checker algorithm

...

The LDRA tool suite V 7.6.0 is able to detect violations of this recommendation.

Compass/ROSE could detect violations of this recommendation by examining every switch statement and ensuring that it has a default clause. (One might forgive a switch statement over an enumerated type that has a clause for every possible value, but as noted above, this statement becomes unsafe if the set of possible values changes.) ROSE should also detect 'fake switches' as well...that is a chain of if statements each checking the value of the same variable. These if statements should always end in an 'else' clause, or they should mathematically cover every possibility. For instance:

Code Block
bgColor#ccccff

  if (x > 0) {
	  /* ... */
  } else if (x < 0) {
    /* ... */
  } else if (x == 0) {
    /* ... */
  }

Related Vulnerabilities

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

...