Versions Compared

Key

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

...

Compliant Solution 2

The local variable ptr should be initialized to a default value, in this case NULL.

Code Block
#define BUF_SIZE 150

void runit(void) {
    char buf[50];
    char *ptr = NULL; /* initialize ptr to 0 */

    memset(buf,0,50);
    strcpy(buf,ptr);
}

void logit(char *str) {
    char buffer[BUF_SIZE];
    int i;
    for (i=0; i < BUF_SIZE; ++i) buffer[i] = '\0';

    strcpy(buffer, str);
    printf("The message: %s\nhas been logged\n",buffer);
}

int main(int argc, char *argv[]) {
    char buf[BUF_SIZE];

    strcpy(buf, argv[1]);
    logit(buf);
    runit();
}

...