From e07cf2b083fcd13c7cceac360010764b74e51800 Mon Sep 17 00:00:00 2001 From: Kevin Lyda <kevin@ie.suberic.net> Date: Fri, 13 Oct 2017 09:26:59 +0100 Subject: [PATCH] Based on caution / feedback from SA. --- cube-test.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cube-test.c b/cube-test.c index a7d08df..df3d2ad 100644 --- a/cube-test.c +++ b/cube-test.c @@ -27,6 +27,7 @@ read_number() { if (!fgets(buf, sizeof buf, stdin)) { return 0; } + buf[9] = 0; return atoi(buf); } @@ -80,9 +81,11 @@ main(int argc, char *argv[]) { guess = read_number(); delta = end_timer(&timer); if (guess == 0) { - printf("Got %d correct out of %d.\n", correct, iterations); - printf("Average time to answer was %s\n", - humanize_usec(delta_total / iterations)); + if (iterations) { + printf("Got %d correct out of %d.\n", correct, iterations); + printf("Average time to answer was %s\n", + humanize_usec(delta_total / iterations)); + } exit(0); } iterations++; -- GitLab