Skip to content

Commit

Permalink
Use C99 snprintf instead of sprintf
Browse files Browse the repository at this point in the history
Since we're already using `vsnprintf` and other C99 features, it's only
natural to use `snprintf` as well. Moreover, `sprintf` is "deprecated" in
Microsoft's CRT in favor of more secure (Microsoft-specific) alternatives
with its use resulting in a warning, while `snprintf` isn't (although
requires recent enough CRT).
  • Loading branch information
mikedld authored and bvdberg committed Apr 4, 2018
1 parent b8f1802 commit c39ed22
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ctest.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ static void color_print(const char* color, const char* text) {
static void sighandler(int signum)
{
char msg[128];
sprintf(msg, "[SIGNAL %d: %s]", signum, sys_siglist[signum]);
snprintf(msg, sizeof(msg), "[SIGNAL %d: %s]", signum, sys_siglist[signum]);
color_print(ANSI_BRED, msg);
fflush(stdout);

Expand Down Expand Up @@ -523,7 +523,7 @@ int ctest_main(int argc, const char *argv[])

const char* color = (num_fail) ? ANSI_BRED : ANSI_GREEN;
char results[80];
sprintf(results, "RESULTS: %d tests (%d ok, %d failed, %d skipped) ran in %" PRIu64 " ms", total, num_ok, num_fail, num_skip, (t2 - t1)/1000);
snprintf(results, sizeof(results), "RESULTS: %d tests (%d ok, %d failed, %d skipped) ran in %" PRIu64 " ms", total, num_ok, num_fail, num_skip, (t2 - t1)/1000);
color_print(color, results);
return num_fail;
}
Expand Down

0 comments on commit c39ed22

Please sign in to comment.