stat: fix integer overflow in convert_agg_kbytes_percent
authorFelix Abecassis <fabecassis@nvidia.com>
Fri, 14 May 2021 00:02:40 +0000 (17:02 -0700)
committerFelix Abecassis <fabecassis@nvidia.com>
Fri, 14 May 2021 00:02:40 +0000 (17:02 -0700)
Assuming that "int" is 32-bit, for high bandwidth values (> 21.5 GB/s)
the expression "mean * 100" will cause an integer overflow before the
conversion to "double" happens.

Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
stat.c

diff --git a/stat.c b/stat.c
index b7222f465f63a4c785ce080f523c89e2ec6c91f1..a8a96c85a4120b0d70dee939c9102fe340565aae 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -462,7 +462,7 @@ static double convert_agg_kbytes_percent(struct group_run_stats *rs, int ddir, i
 {
        double p_of_agg = 100.0;
        if (rs && rs->agg[ddir] > 1024) {
-               p_of_agg = mean * 100 / (double) (rs->agg[ddir] / 1024.0);
+               p_of_agg = mean * 100.0 / (double) (rs->agg[ddir] / 1024.0);
 
                if (p_of_agg > 100.0)
                        p_of_agg = 100.0;