Versions Compared

Key

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

...

In this noncompliant code example, the signal handler handler() is bound to signum.:

Code Block
bgColor#ffcccc
langc
void handler(int signum) {
  if (signal(signum, handler) == SIG_ERR) {
    /* Handle error */
  }
  /* Handle signal */
}
/* ... */
if (signal(SIGUSR1, handler) == SIG_ERR) {
  /* Handle error */
}

...

For persistent platforms, calling the signal() function from within the signal handler is unnecessary.:

Code Block
bgColor#ccccff
langc
void handler(int signum) {
  /* Handle signal */
}
/* ... */
if (signal(SIGUSR1, handler) == SIG_ERR) {
  /* Handle error */
}

...

The following code example resets a signal handler to the system's default behavior.:

Code Block
bgColor#ccccff
langc
void handler(int signum) {
#ifndef WINDOWS
  if (signal(signum, SIG_DFL) == SIG_ERR) {
    /* Handle error */
  }
#endif
  /* Handle signal */
}
/* ... */
if (signal(SIGUSR1, handler) == SIG_ERR) {
  /* Handle error */
}

...

Tool

Version

Checker

Description

Compass/ROSE  Can detect violations of this rule. However, false positives may occur on systems with persistent handlers.
PRQA QA-C
Include Page
PRQA_V
PRQA_V
Warncall -wc signalPartially implemented.

Related Vulnerabilities

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

...