Be a bit more defensive in clat percentile calc and display
authorJens Axboe <axboe@kernel.dk>
Wed, 12 Oct 2011 19:03:45 +0000 (21:03 +0200)
committerJens Axboe <axboe@kernel.dk>
Wed, 12 Oct 2011 19:03:45 +0000 (21:03 +0200)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
stat.c

diff --git a/stat.c b/stat.c
index 702716e2a828cfa020f1ea7a627a5af965eae4dd..48e9d76fac0aa76670287a2ff56856b6559e7b50 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -128,6 +128,9 @@ static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
        while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0)
                len++;
 
        while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0)
                len++;
 
+       if (!len)
+               return;
+
        /*
         * Sort the percentile list. Note that it may already be sorted if
         * we are using the default values, but since it's a short list this
        /*
         * Sort the percentile list. Note that it may already be sorted if
         * we are using the default values, but since it's a short list this
@@ -158,14 +161,15 @@ static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
                                sprintf(fbuf, "%2.2f", plist[j].u.f);
 
                        log_info(" %sth=[%5u]%c", fbuf, plat_idx_to_val(i),
                                sprintf(fbuf, "%2.2f", plist[j].u.f);
 
                        log_info(" %sth=[%5u]%c", fbuf, plat_idx_to_val(i),
-                                       (is_last? '\n' : ','));
+                                       is_last ? '\n' : ',');
 
                        if (is_last)
                                break;
 
                        if (j % 4 == 3) /* for formatting */
                                log_info("\n");
 
                        if (is_last)
                                break;
 
                        if (j % 4 == 3) /* for formatting */
                                log_info("\n");
-                       j++;
+                       if (++j == FIO_IO_U_LIST_MAX_LEN)
+                               break;
                }
        }
 }
                }
        }
 }