Versions Compared

Key

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

...

Code Block
bgColor#FFCCCC
char const *p;
void dont_do_this(void) {
    char const str[] = "This will change";
    p = str; /* dangerous */
    /* ... */
}

void innocuous(void) {
    char const str[] = "Surprise, surprise";
}
/* ... */
dont_do_this();
innocuous();
/* now, it is likely that p is pointing to "Surprise, surprise" */

...

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

...

Code Block
bgColor#ccccff
char const *p;
void is_this_OK(void) {
    char const str[] = "Everything OK?";
    p = str;
    /* ... */
    p = NULL;
}

...

Code Block
bgColor#FFCCCC
char *init_array(void) {
   char array[10];
   /* Initialize array */
   return array;
}

...