]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: fix divide by zero [coverity]
authorKarel Zak <kzak@redhat.com>
Mon, 31 Oct 2022 08:33:24 +0000 (09:33 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 31 Oct 2022 08:33:24 +0000 (09:33 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/calculate.c

index 995e87191db3d28477e853049761a4cf83749427..ad0b15d92d5266d70a2bffce69186488a15c6b6d 100644 (file)
@@ -119,7 +119,9 @@ static void count_column_deviation(struct libscols_table *tb, struct libscols_co
                n++;
                sum += ce->width + extra;
        }
-       st->width_avg = sum / n;
+
+       if (n)
+               st->width_avg = sum / n;
 
        /* count deviation */
        if (n > 1) {