Print this page
11506 smatch resync

@@ -65,11 +65,11 @@
 sval_t sval_type_val(struct symbol *type, long long val)
 {
         sval_t ret;
 
         if (!type)
-                type = &int_ctype;
+                type = &llong_ctype;
 
         ret.type = type;
         ret.value = val;
         return ret;
 }

@@ -92,10 +92,12 @@
         return (sval.type->type == SYM_PTR || sval.type->type == SYM_ARRAY);
 }
 
 int sval_unsigned(sval_t sval)
 {
+        if (is_ptr_type(sval.type))
+                return true;
         return type_unsigned(sval.type);
 }
 
 int sval_signed(sval_t sval)
 {

@@ -456,10 +458,12 @@
                 } else {
                         ret.value = (left.value - right.value) / align;
                 }
         }
 
+        if (op == '-')
+                ret.type = ssize_t_ctype;
         return ret;
 }
 
 sval_t sval_binop(sval_t left, int op, sval_t right)
 {

@@ -581,19 +585,38 @@
         left = sval_cast(type, left);
         right = sval_cast(type, right);
         return sval_binop_overflows(left, op, right);
 }
 
-unsigned long long fls_mask(unsigned long long uvalue)
+int find_first_zero_bit(unsigned long long uvalue)
 {
-        unsigned long long high_bit = 0;
+        int i;
 
+        for (i = 0; i < 64; i++) {
+                if (!(uvalue & (1ULL << i)))
+                        return i;
+        }
+        return i;
+}
+
+int sm_fls64(unsigned long long uvalue)
+{
+        int high_bit = 0;
+
         while (uvalue) {
                 uvalue >>= 1;
                 high_bit++;
         }
 
+        return high_bit;
+}
+
+unsigned long long fls_mask(unsigned long long uvalue)
+{
+        int high_bit = 0;
+
+        high_bit = sm_fls64(uvalue);
         if (high_bit == 0)
                 return 0;
 
         return ((unsigned long long)-1) >> (64 - high_bit);
 }

@@ -605,10 +628,12 @@
 
 const char *sval_to_str(sval_t sval)
 {
         char buf[30];
 
+        if (sval_is_ptr(sval) && sval.value == valid_ptr_max)
+                return "ptr_max";
         if (sval_unsigned(sval) && sval.value == ULLONG_MAX)
                 return "u64max";
         if (sval_unsigned(sval) && sval.value == UINT_MAX)
                 return "u32max";
         if (sval.value == USHRT_MAX)

@@ -636,10 +661,26 @@
                 snprintf(buf, sizeof(buf), "%lld", sval.value);
 
         return alloc_sname(buf);
 }
 
+const char *sval_to_str_or_err_ptr(sval_t sval)
+{
+        char buf[12];
+
+        if (option_project != PROJ_KERNEL ||
+            !is_ptr_type(sval.type))
+                return sval_to_str(sval);
+
+        if (sval.uvalue >= -4905ULL) {
+                snprintf(buf, sizeof(buf), "(%lld)", sval.value);
+                return alloc_sname(buf);
+        }
+
+        return sval_to_str(sval);
+}
+
 const char *sval_to_numstr(sval_t sval)
 {
         char buf[30];
 
         if (sval_unsigned(sval))