return_to_param: Use the DB return strings like "[$->foo]" for indirection
[smatch.git] / check_container_of.c
bloba466739ddab87310d618c95bbfcda97073eeda75
1 /*
2 * Copyright (C) 2010 Dan Carpenter.
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 * Some macros don't return NULL pointers. Complain if people
20 * check the results for NULL because obviously the programmers
21 * don't know what the pants they're doing.
24 #include "smatch.h"
26 static int my_id;
28 STATE(non_null);
30 static void is_ok(struct sm_state *sm, struct expression *mod_expr)
32 set_state(my_id, sm->name, sm->sym, &undefined);
35 static void match_non_null(const char *fn, struct expression *expr, void *unused)
37 set_state_expr(my_id, expr->left, &non_null);
40 static void match_condition(struct expression *expr)
42 if (__in_pre_condition)
43 return;
45 if (get_macro_name(expr->pos))
46 return;
48 if (get_state_expr(my_id, expr) == &non_null) {
49 char *name;
51 name = expr_to_var(expr);
52 sm_msg("warn: can '%s' even be NULL?", name);
53 set_state_expr(my_id, expr, &undefined);
54 free_string(name);
58 void check_container_of(int id)
60 if (option_project != PROJ_KERNEL)
61 return;
63 my_id = id;
64 add_macro_assign_hook("container_of", &match_non_null, NULL);
65 add_macro_assign_hook("list_first_entry", &match_non_null, NULL);
66 add_function_assign_hook("nla_data", &match_non_null, NULL);
67 add_modification_hook(my_id, &is_ok);
68 add_hook(&match_condition, CONDITION_HOOK);