From d2e43c6b39956a9f5f659feb3932416842c5c1c6 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 26 Sep 2023 13:18:42 +0200 Subject: [PATCH] libsmartcols: make sure counter is initialized Signed-off-by: Karel Zak --- libsmartcols/src/filter-param.c | 9 +++++++-- libsmartcols/src/smartcolsP.h | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libsmartcols/src/filter-param.c b/libsmartcols/src/filter-param.c index 1c825b5016..f0cb99ac56 100644 --- a/libsmartcols/src/filter-param.c +++ b/libsmartcols/src/filter-param.c @@ -344,11 +344,15 @@ int filter_count_param(struct libscols_filter *fltr, switch (ct->func) { case SCOLS_COUNTER_MAX: - if (num > ct->result) + if (!ct->has_result) + ct->result = num; + else if (num > ct->result) ct->result = num; break; case SCOLS_COUNTER_MIN: - if (num < ct->result) + if (!ct->has_result) + ct->result = num; + else if (num < ct->result) ct->result = num; break; case SCOLS_COUNTER_SUM: @@ -358,6 +362,7 @@ int filter_count_param(struct libscols_filter *fltr, return -EINVAL; } + ct->has_result = 1; DBG(FLTR, ul_debugobj(fltr, "counted '%s' [result: %llu]", ct->name, ct->result)); return 0; } diff --git a/libsmartcols/src/smartcolsP.h b/libsmartcols/src/smartcolsP.h index a09f0d465b..0af4021c83 100644 --- a/libsmartcols/src/smartcolsP.h +++ b/libsmartcols/src/smartcolsP.h @@ -541,7 +541,8 @@ struct libscols_counter { int func; unsigned long long result; - unsigned int neg : 1; + unsigned int neg : 1, + has_result : 1; }; struct libscols_filter { -- 2.47.3