Versions Compared

Key

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

...

In this solution, the magic number is abstracted and the buffer overflow is eliminated.

Code Block
bgColor#ffcccc#ccccff
enum {max_buffer = 24};

void report_error(char *msg) {
  char *error_log = msg;
  char buffer[max_buffer];

  snprintf(buffer, sizeof( buffer), "Error: %s", error_log);
  printf("%s\n", buffer);
}

...