Versions Compared

Key

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

...

Code Block
bgColor#ccccff
langc
#include <stdio.h>
 
extern void f(int i);
 
int func(int expr) {

  /*
   * Move the code outside the switch block,; now the statements
   * will get executed.
   */
  int i = 4;
  f(i);

  switch (expr) {
    case 0:
      i = 17;
      /* Falls through into default code */
    default:
      printf("€œ%d\n"€, i);
  }
  return 0;
}

...

Using test conditions or initializing variables before the first case statement in a switch block can result in unexpected behavior and undefined behavior.

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

DCL41-C

Medium

Unlikely

Medium

P4

L3

...