From 21fae3d1d943eaf88aa3c0f04f0358604c0fe862 Mon Sep 17 00:00:00 2001 From: Mat Martineau Date: Tue, 11 Jul 2017 16:10:19 -0700 Subject: [PATCH] test-runner: Avoid intermediate string in number conversion Derive a floating-point interval value from integers using math rather than integer->string->float conversion. The string technique triggered a -Wformat-overflow warning. --- tools/test-runner.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tools/test-runner.c b/tools/test-runner.c index 3e07d20b..f30b970e 100644 --- a/tools/test-runner.c +++ b/tools/test-runner.c @@ -1380,8 +1380,6 @@ start_next_test: pid_t corpse; int status; double interval; - const int BUF_LEN = 11; - char interval_buf[BUF_LEN]; corpse = waitpid(WAIT_ANY, &status, 0); @@ -1394,11 +1392,8 @@ start_next_test: kill_process(test_timer_pid); timersub(&time_after, &time_before, &time_elapsed); - sprintf(interval_buf, "%ld.%0ld", - (long int) time_elapsed.tv_sec, - (long int) time_elapsed.tv_usec); - interval_buf[BUF_LEN - 1] = '\0'; - interval = atof(interval_buf); + interval = time_elapsed.tv_sec + + 1e-6 * time_elapsed.tv_usec; if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS) {