param_cleared: handle direct assignments
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 19 Jun 2014 06:52:22 +0000 (19 09:52 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Thu, 19 Jun 2014 06:52:22 +0000 (19 09:52 +0300)
If you assign a struct that means it's members are cleared out.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch_param_cleared.c

index 65f060e..69bc6bb 100644 (file)
@@ -139,6 +139,16 @@ static void match_usb_control_msg(const char *fn, struct expression *expr, void
        db_param_cleared(expr, 6, (char *)"$$", (char *)"");
 }
 
+static void match_assign(struct expression *expr)
+{
+       struct symbol *type;
+
+       type = get_type(expr->left);
+       if (!type || type->type != SYM_STRUCT)
+               return;
+       set_state_expr(my_id, expr->left, &cleared);
+}
+
 void register_param_cleared(int id)
 {
        my_id = id;
@@ -154,6 +164,8 @@ void register_param_cleared(int id)
        add_function_hook("sprintf", &match_memcpy, INT_PTR(0));
        add_function_hook("snprintf", &match_memcpy, INT_PTR(0));
 
+       add_hook(&match_assign, ASSIGNMENT_HOOK);
+
        register_clears_param();
 
        select_return_states_hook(PARAM_CLEARED, &db_param_cleared);