From ffacfb2963404c6a5866073404e585fac0c19429 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 31 Oct 2022 09:33:24 +0100 Subject: [PATCH] libsmartcols: fix divide by zero [coverity] Signed-off-by: Karel Zak --- libsmartcols/src/calculate.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libsmartcols/src/calculate.c b/libsmartcols/src/calculate.c index 995e87191d..ad0b15d92d 100644 --- a/libsmartcols/src/calculate.c +++ b/libsmartcols/src/calculate.c @@ -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) { -- 2.47.3