Print this page
11506 smatch resync
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/check_wine_WtoA.c
+++ new/usr/src/tools/smatch/src/check_wine_WtoA.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 *
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
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 /*
19 - * Idea from Michael Stefaniuc and Vincent Béron's earlier WtoA
19 + * Idea from Michael Stefaniuc and Vincent Béron's earlier WtoA
20 20 * check.
21 21 *
22 22 * Apparently when you are coding WINE, you are not allowed to call
23 23 * functions that end in capital 'A' from functions that end in
24 24 * capital 'W'
25 25 *
26 26 */
27 27
28 28 #include "smatch.h"
29 29
30 30 static int my_id;
31 31
32 32 static int in_w = 0;
33 33
34 34 static void match_function_def(struct symbol *sym)
35 35 {
36 36 char *func = get_function();
37 37 int len;
38 38
39 39 if (!func) {
40 40 in_w = 0;
41 41 return;
42 42 }
43 43 len = strlen(func);
44 44 if (func[len - 1] == 'W' && len > 2 && func[len - 2] != 'A' )
45 45 in_w = 1;
46 46 else
47 47 in_w = 0;
48 48 }
49 49
50 50 static int allowed_func(const char *fn)
51 51 {
52 52 if (!strcmp("lstrcatA", fn))
53 53 return 1;
54 54 if (!strcmp("lstrcpyA", fn))
55 55 return 1;
56 56 if (!strcmp("lstrcpynA", fn))
57 57 return 1;
58 58 if (!strcmp("lstrlenA", fn))
59 59 return 1;
60 60 return 0;
61 61 }
62 62
63 63 static void match_call(struct expression *expr)
64 64 {
65 65 char *fn_name;
66 66 int len;
67 67
68 68 if (!in_w)
69 69 return;
70 70
71 71 fn_name = expr_to_var(expr->fn);
72 72 if (!fn_name)
73 73 goto free;
74 74 len = strlen(fn_name);
75 75 if (fn_name[len - 1] == 'A' && !allowed_func(fn_name)) {
76 76 sm_warning("WtoA call '%s()'", fn_name);
77 77 }
78 78 free:
79 79 free_string(fn_name);
80 80 }
81 81
82 82 void check_wine_WtoA(int id)
83 83 {
84 84 if (option_project != PROJ_WINE)
85 85 return;
86 86
87 87 my_id = id;
88 88 add_hook(&match_function_def, FUNC_DEF_HOOK);
89 89 add_hook(&match_call, FUNCTION_CALL_HOOK);
90 90 }
↓ open down ↓ |
61 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX