Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Clarified code comments.

...

Code Block
bgColor#FFcccc
void f() {
  char path[PATH_MAX];
  /* assume $PATH must be defined is defined and no longer than PATH_MAX characters */
  strcpy(path, getenv("PATH"));
  /* use path */
}

...

Code Block
bgColor#ccccff
void f() {
  char *copy = NULL;
  /* avoid assuming $PATH must be defined is defined or has limited length */
  const char *temp = getenv("PATH");
  if (temp != NULL) {
    path = (char*) malloc(strlen(temp) + 1);
    if (copy == NULL) {
      /* Handle error condition */
    } else {
      strcpy(path, temp);
    }
    /* use path */
  }
}

...