Print this page
12166 resync smatch to 0.6.1-rc1-il-3
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/check_frees_param.c
+++ new/usr/src/tools/smatch/src/check_frees_param.c
1 1 /*
2 2 * Copyright (C) 2014 Oracle.
3 3 *
4 4 * This program is free software; you can redistribute it and/or
5 5 * modify it under the terms of the GNU General Public License
6 6 * as published by the Free Software Foundation; either version 2
7 7 * of the License, or (at your option) any later version.
8 8 *
9 9 * This program is distributed in the hope that it will be useful,
10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 * GNU General Public License for more details.
13 13 *
14 14 * You should have received a copy of the GNU General Public License
15 15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16 16 */
17 17
18 18 /*
19 19 * This file is sort of like check_dereferences_param.c. In theory the one
20 20 * difference should be that the param is NULL it should still be counted as a
21 21 * free. But for now I don't handle that case.
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
22 22 */
23 23
24 24 #include "smatch.h"
25 25 #include "smatch_extra.h"
26 26 #include "smatch_slist.h"
27 27
28 28 static int my_id;
29 29
30 30 STATE(freed);
31 31 STATE(ignore);
32 -STATE(param);
33 32
34 33 static void set_ignore(struct sm_state *sm, struct expression *mod_expr)
35 34 {
36 35 set_state(my_id, sm->name, sm->sym, &ignore);
37 36 }
38 37
39 -static void match_function_def(struct symbol *sym)
40 -{
41 - struct symbol *arg;
42 - int i;
43 -
44 - i = -1;
45 - FOR_EACH_PTR(sym->ctype.base_type->arguments, arg) {
46 - i++;
47 - if (!arg->ident)
48 - continue;
49 - set_state(my_id, arg->ident->name, arg, ¶m);
50 - } END_FOR_EACH_PTR(arg);
51 -}
52 -
53 38 static void freed_variable(struct expression *expr)
54 39 {
55 40 struct sm_state *sm;
56 41
57 42 expr = strip_expr(expr);
58 43 if (get_param_num(expr) < 0)
59 44 return;
60 45
61 46 sm = get_sm_state_expr(my_id, expr);
62 47 if (sm && slist_has_state(sm->possible, &ignore))
63 48 return;
64 49 set_state_expr(my_id, expr, &freed);
65 50 }
66 51
67 52 static void match_free(const char *fn, struct expression *expr, void *param)
68 53 {
69 54 struct expression *arg;
70 55
71 56 arg = get_argument_from_call_expr(expr->args, PTR_INT(param));
72 57 if (!arg)
73 58 return;
74 59 freed_variable(arg);
75 60 }
76 61
77 62 static void set_param_freed(struct expression *call, struct expression *arg, char *key, char *unused)
78 63 {
79 64 /* XXX FIXME: return_implies has been updated with more information */
80 65 if (strcmp(key, "$") != 0)
81 66 return;
82 67 freed_variable(arg);
83 68 }
84 69
85 70 static void process_states(void)
86 71 {
87 72 struct sm_state *sm;
88 73 int param;
89 74 const char *param_name;
90 75
91 76 FOR_EACH_MY_SM(my_id, __get_cur_stree(), sm) {
92 77 if (sm->state != &freed)
93 78 continue;
94 79 param = get_param_num_from_sym(sm->sym);
95 80 if (param < 0)
96 81 continue;
97 82 param_name = get_param_name(sm);
98 83 if (!param_name)
99 84 continue;
100 85 sql_insert_return_implies(PARAM_FREED, param, param_name, "1");
101 86 } END_FOR_EACH_SM(sm);
102 87
103 88 }
↓ open down ↓ |
41 lines elided |
↑ open up ↑ |
104 89
105 90 void check_frees_param(int id)
106 91 {
107 92 my_id = id;
108 93
109 94 if (option_project == PROJ_KERNEL) {
110 95 /* The kernel uses check_frees_param_strict.c */
111 96 return;
112 97 }
113 98
114 - add_hook(&match_function_def, FUNC_DEF_HOOK);
115 -
116 99 add_function_hook("free", &match_free, INT_PTR(0));
117 100
118 101 select_return_implies_hook(PARAM_FREED, &set_param_freed);
119 102 add_modification_hook(my_id, &set_ignore);
120 103
121 104 all_return_states_hook(&process_states);
122 105 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX