]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: prefer float in filter expression
authorKarel Zak <kzak@redhat.com>
Thu, 2 Nov 2023 12:44:32 +0000 (13:44 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 20 Nov 2023 21:25:47 +0000 (22:25 +0100)
Reported-by: Masatake YAMATO <yamato@redhat.com>
Addresses: https://github.com/util-linux/util-linux/pull/2531#discussion_r1373797202
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/filter-expr.c

index d3229d00eb843a2bc51a6cef161a005188de3984..16a476bde8efe4150972cac9d657644412b66f44 100644 (file)
@@ -141,7 +141,7 @@ static int guess_expr_datatype(struct filter_expr *n)
 {
        int type;
        int l = node_get_datatype(n->left),
-                        r = node_get_datatype(n->right);
+           r = node_get_datatype(n->right);
 
        if (l == r)
                type = l;
@@ -159,6 +159,11 @@ static int guess_expr_datatype(struct filter_expr *n)
                        type = l;
                else
                        type = l;
+
+               /* Always prefer float before number */
+               if (type == SCOLS_DATA_U64
+                   && (r == SCOLS_DATA_FLOAT || l == SCOLS_DATA_FLOAT))
+                       type = SCOLS_DATA_FLOAT;
        }
 
        DBG(FPARAM, ul_debugobj(n, " expr datatype: %d", type));