crc/test: fix potential div by zero
authorJens Axboe <axboe@fb.com>
Wed, 15 Oct 2014 01:47:41 +0000 (19:47 -0600)
committerJens Axboe <axboe@fb.com>
Wed, 15 Oct 2014 01:47:41 +0000 (19:47 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
crc/test.c

index bca46f243cf25077ddc4f43b596dc7fca2c19ab6..bc5cc45658ec4818e3b57ef9f03927c9f1c6bc29 100644 (file)
@@ -329,13 +329,16 @@ int fio_crctest(const char *type)
                t[i].fn(&t[i], buf, CHUNK);
                usec = utime_since_now(&tv);
 
-               mb_sec = (double) mb / (double) usec;
-               mb_sec /= (1.024 * 1.024);
-               if (strlen(t[i].name) >= 7)
-                       sprintf(pre, "\t");
-               else
-                       sprintf(pre, "\t\t");
-               printf("%s:%s%8.2f MB/sec\n", t[i].name, pre, mb_sec);
+               if (usec) {
+                       mb_sec = (double) mb / (double) usec;
+                       mb_sec /= (1.024 * 1.024);
+                       if (strlen(t[i].name) >= 7)
+                               sprintf(pre, "\t");
+                       else
+                               sprintf(pre, "\t\t");
+                       printf("%s:%s%8.2f MB/sec\n", t[i].name, pre, mb_sec);
+               } else
+                       printf("%s:inf MB/sec\n", t[i].name);
                first = 0;
        }