diff --git a/cube-test.c b/cube-test.c
index a7d08dff683f563f08c18238ae39e63a111c8c6d..df3d2adbc99bbb283de4be45a9eff45727759cb1 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++;