Versions Compared

Key

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

...

Code Block
bgColor#FFCCCC
char msg[100];
/* ... */
void report_error(const char *error_msg) {
  char msg[80];
  /* ... */
  /* Assume error_msg isn't too long */
  strcpy(msg, error_msg);
  return;
}

int main(void) {
  /* ... */
  /* Ensure error_msg isn't too long */
  if (strlen( error_msg) >= sizeof( msg)) {
    error_msg[sizeof(msg) - 1] = '\0';
  }
  report_error( error_msg); /* oops! */
  /* ... */
}

...

Code Block
bgColor#ccccff
char system_msg[100];
/* ... */
void report_error(const char *error_msg) {
  char default_msg[80];
  /* ... */
  /* Assume error_msg isn't too long */
  strcpy(system_msg, error_msg);
  return;
}
int main(void) {
  /* ... */
  /* Ensure error_msg isn't too long */
  if (strlen( error_msg) >= sizeof( system_msg)) {
    error_msg[sizeof(msg) - 1] = '\0';
  }
  report_error( error_msg); /* good */
 /* ... */
}

...