...
In this solution, the magic number is abstracted and the buffer overflow is eliminated.
Code Block | ||
---|---|---|
| ||
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); } |
...