Print this page
12724 update smatch to 0.6.1-rc1-il-5

@@ -549,10 +549,20 @@
         if (expr->string)
                 return 1;
         return 0;
 }
 
+bool is_struct_ptr(struct symbol *type)
+{
+        if (!type || type->type != SYM_PTR)
+                return false;
+        type = get_real_base_type(type);
+        if (!type || type->type != SYM_STRUCT)
+                return false;
+        return true;
+}
+
 int is_static(struct expression *expr)
 {
         char *name;
         struct symbol *sym;
         int ret = 0;

@@ -593,10 +603,27 @@
         if (type_positive_bits(one) != type_positive_bits(two))
                 return 0;
         return 1;
 }
 
+bool type_fits(struct symbol *type, struct symbol *test)
+{
+        if (!type || !test)
+                return false;
+
+        if (type == test)
+                return true;
+
+        if (type_bits(test) > type_bits(type))
+                return false;
+        if (type_signed(test) && !type_signed(type))
+                return false;
+        if (type_positive_bits(test) > type_positive_bits(type))
+                return false;
+        return true;
+}
+
 int fn_static(void)
 {
         return !!(cur_func_sym->ctype.modifiers & MOD_STATIC);
 }
 

@@ -683,10 +710,12 @@
 }
 
 struct symbol *get_member_type_from_key(struct expression *expr, const char *key)
 {
         struct symbol *sym;
+        int star = 0;
+        int i;
 
         if (strcmp(key, "$") == 0)
                 return get_type(expr);
 
         if (strcmp(key, "*$") == 0) {

@@ -700,15 +729,30 @@
         if (!sym)
                 return NULL;
         if (sym->type == SYM_PTR)
                 sym = get_real_base_type(sym);
 
-        key = key + 1;
+        while (*key == '*') {
+                key++;
+                star++;
+        }
+
+        if (*key != '$')
+                return NULL;
+        key++;
+
         sym = get_member_from_string(sym->symbol_list, key);
         if (!sym)
                 return NULL;
-        return get_real_base_type(sym);
+        if (sym->type == SYM_RESTRICT || sym->type == SYM_NODE)
+                sym = get_real_base_type(sym);
+        for (i = 0; i < star; i++) {
+                if (!sym || sym->type != SYM_PTR)
+                        return NULL;
+                sym = get_real_base_type(sym);
+        }
+        return sym;
 }
 
 struct symbol *get_arg_type_from_key(struct expression *fn, int param, struct expression *arg, const char *key)
 {
         struct symbol *type;