Versions Compared

Key

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

...

Code Block
bgColor#ffcccc
#include <signal.h>

size_t i;

void handler() {
  i = 0;
}

int main(void) {
  signal(SIGINT, handler);
  i = 1;
  while (i) {
   /* do something */
  }
}

Compliant Solution

By adding the volatile qualifier, i is guaranteed to be accessed from it original address for every iteration of the while loop.

Code Block
bgColor#ccccff
#include <signal.h>

volatile size_t i;

void handler() {
  i = 0;
}

int main(void) {
  signal(SIGINT, handler);
  i = 1;
  while (i) {
   /* do something */
  }
}

Risk Assessment

In addition to incorrect optimizations, this can cause race conditions, resulting in Omitting the restrict qualification for objects that can change in ways unexpected to the implementation can lead to unexpected program flow or an inconsistent state.

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

DCL34-C

2 (medium)

2 (probable)

2 (medium)

P8

L2

...