sval: cast things correctly in sval_cmp()
authorDan Carpenter <dan.carpenter@oracle.com>
Mon, 19 Nov 2012 13:07:56 +0000 (19 16:07 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Mon, 19 Nov 2012 13:07:56 +0000 (19 16:07 +0300)
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 <dan.carpenter@oracle.com>
smatch_sval.c

index 0077468..054c82b 100644 (file)
@@ -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)