Print this page
new smatch
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/check_deref_check.c
+++ new/usr/src/tools/smatch/src/check_deref_check.c
1 1 /*
2 2 * Copyright (C) 2009 Dan Carpenter.
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 #include "smatch.h"
19 19 #include "smatch_extra.h"
20 20
21 21 static int my_id;
22 22
23 23 STATE(derefed);
24 24
25 25 static void underef(struct sm_state *sm, struct expression *mod_expr)
26 26 {
27 27 set_state(my_id, sm->name, sm->sym, &undefined);
28 28 }
29 29
30 30 static void match_dereference(struct expression *expr)
31 31 {
32 32 if (__in_fake_assign)
33 33 return;
34 34
35 35 if (expr->type != EXPR_PREOP)
36 36 return;
37 37 expr = strip_expr(expr->unop);
38 38 if (!is_pointer(expr))
39 39 return;
40 40 if (implied_not_equal(expr, 0))
41 41 return;
42 42
43 43 if (is_impossible_path())
44 44 return;
45 45
46 46 set_state_expr(my_id, expr, &derefed);
47 47 }
48 48
49 49 static void set_param_dereferenced(struct expression *call, struct expression *arg, char *key, char *unused)
50 50 {
51 51 struct symbol *sym;
52 52 char *name;
53 53
54 54 name = get_variable_from_key(arg, key, &sym);
55 55 if (!name || !sym)
56 56 goto free;
57 57
58 58 if (implied_not_equal_name_sym(name, sym, 0))
↓ open down ↓ |
58 lines elided |
↑ open up ↑ |
59 59 goto free;
60 60 set_state(my_id, name, sym, &derefed);
61 61
62 62 free:
63 63 free_string(name);
64 64 }
65 65
66 66 static void match_condition(struct expression *expr)
67 67 {
68 68 struct sm_state *sm;
69 + char *name;
69 70
70 71 if (__in_pre_condition)
71 72 return;
72 73
73 - if (get_macro_name(expr->pos))
74 + name = get_macro_name(expr->pos);
75 + if (name &&
76 + (strcmp(name, "likely") != 0 && strcmp(name, "unlikely") != 0))
74 77 return;
75 78
76 79 if (!is_pointer(expr))
77 80 return;
78 81
79 82 sm = get_sm_state_expr(my_id, expr);
80 83 if (!sm || sm->state != &derefed)
81 84 return;
82 85
83 86 sm_warning("variable dereferenced before check '%s' (see line %d)", sm->name, sm->line);
84 87 set_state_expr(my_id, expr, &undefined);
85 88 }
86 89
87 90 void check_deref_check(int id)
88 91 {
89 92 my_id = id;
90 93 add_hook(&match_dereference, DEREF_HOOK);
91 94 add_hook(&match_condition, CONDITION_HOOK);
92 95 select_return_implies_hook(DEREFERENCE, &set_param_dereferenced);
93 96 add_modification_hook(my_id, &underef);
94 97 }
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX