From: Karel Zak Date: Tue, 26 Sep 2023 11:18:42 +0000 (+0200) Subject: libsmartcols: make sure counter is initialized X-Git-Tag: v2.40-rc1~151^2~53 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d2e43c6b39956a9f5f659feb3932416842c5c1c6;p=thirdparty%2Futil-linux.git libsmartcols: make sure counter is initialized Signed-off-by: Karel Zak --- 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 {