49 static void set_param_dereferenced(struct expression *call, struct expression *arg, char *key, char *unused)
50 {
51 struct symbol *sym;
52 char *name;
53
54 name = get_variable_from_key(arg, key, &sym);
55 if (!name || !sym)
56 goto free;
57
58 if (implied_not_equal_name_sym(name, sym, 0))
59 goto free;
60 set_state(my_id, name, sym, &derefed);
61
62 free:
63 free_string(name);
64 }
65
66 static void match_condition(struct expression *expr)
67 {
68 struct sm_state *sm;
69
70 if (__in_pre_condition)
71 return;
72
73 if (get_macro_name(expr->pos))
74 return;
75
76 if (!is_pointer(expr))
77 return;
78
79 sm = get_sm_state_expr(my_id, expr);
80 if (!sm || sm->state != &derefed)
81 return;
82
83 sm_warning("variable dereferenced before check '%s' (see line %d)", sm->name, sm->line);
84 set_state_expr(my_id, expr, &undefined);
85 }
86
87 void check_deref_check(int id)
88 {
89 my_id = id;
90 add_hook(&match_dereference, DEREF_HOOK);
91 add_hook(&match_condition, CONDITION_HOOK);
92 select_return_implies_hook(DEREFERENCE, &set_param_dereferenced);
93 add_modification_hook(my_id, &underef);
|
49 static void set_param_dereferenced(struct expression *call, struct expression *arg, char *key, char *unused)
50 {
51 struct symbol *sym;
52 char *name;
53
54 name = get_variable_from_key(arg, key, &sym);
55 if (!name || !sym)
56 goto free;
57
58 if (implied_not_equal_name_sym(name, sym, 0))
59 goto free;
60 set_state(my_id, name, sym, &derefed);
61
62 free:
63 free_string(name);
64 }
65
66 static void match_condition(struct expression *expr)
67 {
68 struct sm_state *sm;
69 char *name;
70
71 if (__in_pre_condition)
72 return;
73
74 name = get_macro_name(expr->pos);
75 if (name &&
76 (strcmp(name, "likely") != 0 && strcmp(name, "unlikely") != 0))
77 return;
78
79 if (!is_pointer(expr))
80 return;
81
82 sm = get_sm_state_expr(my_id, expr);
83 if (!sm || sm->state != &derefed)
84 return;
85
86 sm_warning("variable dereferenced before check '%s' (see line %d)", sm->name, sm->line);
87 set_state_expr(my_id, expr, &undefined);
88 }
89
90 void check_deref_check(int id)
91 {
92 my_id = id;
93 add_hook(&match_dereference, DEREF_HOOK);
94 add_hook(&match_condition, CONDITION_HOOK);
95 select_return_implies_hook(DEREFERENCE, &set_param_dereferenced);
96 add_modification_hook(my_id, &underef);
|