Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fixing RA colors

...

Code Block
bgColor#FFCCCC
langcpp

int test (int x) {
  x--;
  if (x < 0 || x > 10) {
    return 0;
  }
  else {
    static int y = test(x);  //<--undefined behavior occurs here
    return y;
  }
}

...

In the GCC Version 4 compiler, upon reaching the initialization of y for the second time, the program will terminate with the following message:

Code Block

terminate called after throwing an instance of
'__gnu_cxx::recursive_init'
  what():  N9__gnu_cxx14recursive_initE
Aborted (core dumped)

...

Code Block
bgColor#ccccff
langcpp

int test (int x) {
  x--;
  if (x < 0 || x > 10) {
    return 0;
  }
  else {
    static int y;
    y = test(x);  
    return y;
  }
}

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

DCL38-CPP

low

unlikely

medium

P2

L3

Related Vulnerabilities

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

...