Versions Compared

Key

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

...

In this compliant solution, p is declared with the same scope as c_str, preventing p from taking on an indeterminate value outside of this_is_OK().:

Code Block
bgColor#ccccff
langc
void this_is_OK(void) {
    const char c_str[] = "Everything OK";
    const char *p = c_str;
    /* ... */
}
/* p is inaccessible outside the scope of string c_str */

...

Bibliography

[Coverity 2007] 
[ISO/IEC 9899:2011]Subclause 6.2.4, "Storage Durations of Objects"

...