From 5de1dfbb0f5a28fc8d4c3dfc28898bf0090a3703 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 19 Nov 2012 16:07:56 +0300 Subject: [PATCH] sval: cast things correctly in sval_cmp() The problem here is that if we wanted to cast both sides to u32 the original code would count negative numbers as high u64 values. We need to actually do the cast before doing the comparison. Signed-off-by: Dan Carpenter --- smatch_sval.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/smatch_sval.c b/smatch_sval.c index 00774683..054c82bb 100644 --- a/smatch_sval.c +++ b/smatch_sval.c @@ -164,12 +164,18 @@ int sval_is_a_max(sval_t sval) */ int sval_cmp(sval_t one, sval_t two) { - sval_t tmp; + struct symbol *type; - tmp = one; + type = one.type; if (sval_positive_bits(two) > sval_positive_bits(one)) - tmp = two; - if (sval_bits(tmp) >= 32 && sval_unsigned(tmp)) { + type = two.type; + if (type_bits(type) < 31) + type = &int_ctype; + + one = sval_cast(type, one); + two = sval_cast(type, two); + + if (type_unsigned(type)) { if (one.uvalue < two.uvalue) return -1; if (one.uvalue == two.uvalue) -- 2.11.4.GIT