]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: make sure counter is initialized
authorKarel Zak <kzak@redhat.com>
Tue, 26 Sep 2023 11:18:42 +0000 (13:18 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 20 Nov 2023 21:25:46 +0000 (22:25 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/filter-param.c
libsmartcols/src/smartcolsP.h

index 1c825b501608d94ab41475e5f9921858dc1d1bb3..f0cb99ac56103ec28d43ce6ecbd681feb47014d0 100644 (file)
@@ -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;
 }
index a09f0d465bf835755da821e549d50790e7630839..0af4021c83870f0a8183e0255065cbea0d150204 100644 (file)
@@ -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 {