2 * Copyright (C) 2012 Oracle.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
19 * This is an --info recipe. The goal is to print a message for every parameter
20 * which we can not avoid dereferencing. This is maybe a bit restrictive but it
21 * avoids some false positives.
25 #include "smatch_extra.h"
26 #include "smatch_slist.h"
32 static void process_states(void)
38 FOR_EACH_MY_SM(my_id
, __get_cur_stree(), tmp
) {
39 if (tmp
->state
!= &derefed
)
41 arg
= get_param_num_from_sym(tmp
->sym
);
44 name
= get_param_name(tmp
);
45 if (!name
|| name
[0] == '&')
47 sql_insert_return_implies(DEREFERENCE
, arg
, name
, "1");
48 } END_FOR_EACH_SM(tmp
);
51 static void deref_hook(struct expression
*expr
)
53 char *param_name
= NULL
;
54 struct symbol
*sym
, *param_sym
;
57 name
= expr_to_var_sym(expr
, &sym
);
61 param_name
= get_param_var_sym_var_sym(name
, sym
, NULL
, ¶m_sym
);
62 if (!param_name
|| !param_sym
)
64 if (get_param_num_from_sym(param_sym
) < 0)
66 if (param_was_set_var_sym(param_name
, param_sym
))
69 set_state(my_id
, param_name
, param_sym
, &derefed
);
74 void check_dereferences_param(int id
)
78 add_dereference_hook(deref_hook
);
79 all_return_states_hook(&process_states
);