Print this page
12724 update smatch to 0.6.1-rc1-il-5
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/check_err_ptr.c
+++ new/usr/src/tools/smatch/src/check_err_ptr.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_slist.h"
20 20
21 21 static int my_id;
22 22
23 23 static int err_ptr = 0;
24 24 static int returns_null = 0;
25 25
26 26 static void match_err_ptr(struct expression *expr)
27 27 {
28 28 expr = strip_expr(expr);
29 29 if (!expr)
↓ open down ↓ |
29 lines elided |
↑ open up ↑ |
30 30 return;
31 31 if (expr->type != EXPR_CALL)
32 32 return;
33 33
34 34 if (expr->fn->type != EXPR_SYMBOL || !expr->fn->symbol)
35 35 return;
36 36 if (!strcmp(expr->fn->symbol->ident->name, "ERR_PTR"))
37 37 err_ptr = 1;
38 38 }
39 39
40 -extern int check_assigned_expr_id;
41 40 static void match_return(struct expression *ret_value)
42 41 {
43 42 struct state_list *slist;
44 43 struct sm_state *tmp;
45 44 sval_t sval;
46 45
47 46 if (__inline_fn)
48 47 return;
49 48 match_err_ptr(ret_value);
50 49 slist = get_possible_states_expr(check_assigned_expr_id, ret_value);
51 50 FOR_EACH_PTR(slist, tmp) {
52 51 if (tmp->state == &undefined || tmp->state == &merged)
53 52 continue;
54 53 match_err_ptr((struct expression *)tmp->state->data);
55 54 } END_FOR_EACH_PTR(tmp);
56 55
57 56 if (get_implied_value(ret_value, &sval)) {
58 57 if (sval.value == 0)
59 58 returns_null = 1;
60 59 }
61 60 }
62 61
63 62 static void match_end_func(struct symbol *sym)
64 63 {
65 64 if (__inline_fn)
66 65 return;
67 66 if (err_ptr)
68 67 sm_info("returns_err_ptr");
69 68 err_ptr = 0;
70 69 returns_null = 0;
71 70 }
72 71
73 72 void check_err_ptr(int id)
74 73 {
75 74 if (option_project != PROJ_KERNEL)
76 75 return;
77 76 if (!option_info)
78 77 return;
79 78
80 79 my_id = id;
81 80 add_hook(&match_return, RETURN_HOOK);
82 81 add_hook(&match_end_func, END_FUNC_HOOK);
83 82 }
↓ open down ↓ |
33 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX