...
In this noncompliant code example, strcat()
and strcpy()
are used.
Code Block | ||||
---|---|---|---|---|
| ||||
enum { BUFFERSIZE=256 }; void complain(const char *msg) { static const char prefix[] = "Error: "; static const char suffix[] = "\n"; char buf[BUFFERSIZE]; strcpy(buf, prefix); strcat(buf, msg); strcat(buf, suffix); fputs(buf, stderr); } |
...
In this compliant solution, strcat()
and strcpy()
are replaced by strcat_s()
and strcpy_s()
.
Code Block | ||||
---|---|---|---|---|
| ||||
enum { BUFFERSIZE=256 }; void complain(const char *msg) { static const char prefix[] = "Error: "; static const char suffix[] = "\n"; char buf[BUFFERSIZE]; strcpy_s(buf, BUFFERSIZE, prefix); strcat_s(buf, BUFFERSIZE, msg); strcat_s(buf, BUFFERSIZE, suffix); fputs(buf, stderr); } |
...