From: Dan Carpenter Date: Mon, 19 Nov 2012 13:07:56 +0000 (+0300) Subject: sval: cast things correctly in sval_cmp() X-Git-Tag: 1.57~192 X-Git-Url: https://repo.or.cz/w/smatch.git/commitdiff_plain/5de1dfbb0f5a28fc8d4c3dfc28898bf0090a3703 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 --- 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)