sval: extra: type information was being lost in ++/-- operations
[smatch.git] / check_container_of.c
blob0f254cd25c6b765da2394c5486182f50d57c15fb
1 /*
2 * smatch/check_container_of.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
9 /*
10 * Some macros don't return NULL pointers. Complain if people
11 * check the results for NULL because obviously the programmers
12 * don't know what the pants they're doing.
15 #include "smatch.h"
17 static int my_id;
19 STATE(non_null);
21 static void is_ok(struct sm_state *sm)
23 set_state(my_id, sm->name, sm->sym, &undefined);
26 static void match_non_null(const char *fn, struct expression *expr, void *unused)
28 set_state_expr(my_id, expr->left, &non_null);
31 static void match_condition(struct expression *expr)
33 if (__in_pre_condition)
34 return;
36 if (get_macro_name(expr->pos))
37 return;
39 if (get_state_expr(my_id, expr) == &non_null) {
40 char *name;
42 name = get_variable_from_expr(expr, NULL);
43 sm_msg("warn: can '%s' even be NULL?", name);
44 set_state_expr(my_id, expr, &undefined);
45 free_string(name);
49 void check_container_of(int id)
51 if (option_project != PROJ_KERNEL)
52 return;
54 my_id = id;
55 add_macro_assign_hook("container_of", &match_non_null, NULL);
56 add_macro_assign_hook("list_first_entry", &match_non_null, NULL);
57 add_modification_hook(my_id, &is_ok);
58 add_hook(&match_condition, CONDITION_HOOK);