free_strict: print the line number where the pointer was freed
[smatch.git] / check_container_of.c
blob04b295d704fbfbb3e9626703c545f367ba9de577
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 match_non_null(const char *fn, struct expression *expr, void *unused)
32 set_state_expr(my_id, expr->left, &non_null);
35 static void match_condition(struct expression *expr)
37 if (__in_pre_condition)
38 return;
40 if (get_macro_name(expr->pos))
41 return;
43 if (get_state_expr(my_id, expr) == &non_null) {
44 char *name;
46 name = expr_to_var(expr);
47 sm_warning("can '%s' even be NULL?", name);
48 set_state_expr(my_id, expr, &undefined);
49 free_string(name);
53 void check_container_of(int id)
55 if (option_project != PROJ_KERNEL)
56 return;
58 my_id = id;
59 add_macro_assign_hook("container_of", &match_non_null, NULL);
60 add_macro_assign_hook("list_first_entry", &match_non_null, NULL);
61 add_function_assign_hook("nla_data", &match_non_null, NULL);
62 add_modification_hook(my_id, &set_undefined);
63 add_hook(&match_condition, CONDITION_HOOK);