math: array parameters can be NULL
[smatch.git] / check_wine_WtoA.c
blobf074471bd700c5237675bde85104dc9204a1d785
1 /*
2 * Copyright (C) 2009 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 * Idea from Michael Stefaniuc and Vincent BĂ©ron's earlier WtoA
20 * check.
22 * Apparently when you are coding WINE, you are not allowed to call
23 * functions that end in capital 'A' from functions that end in
24 * capital 'W'
28 #include "smatch.h"
30 static int my_id;
32 static int in_w = 0;
34 static void match_function_def(struct symbol *sym)
36 char *func = get_function();
37 int len;
39 if (!func) {
40 in_w = 0;
41 return;
43 len = strlen(func);
44 if (func[len - 1] == 'W' && len > 2 && func[len - 2] != 'A' )
45 in_w = 1;
46 else
47 in_w = 0;
50 static int allowed_func(const char *fn)
52 if (!strcmp("lstrcatA", fn))
53 return 1;
54 if (!strcmp("lstrcpyA", fn))
55 return 1;
56 if (!strcmp("lstrcpynA", fn))
57 return 1;
58 if (!strcmp("lstrlenA", fn))
59 return 1;
60 return 0;
63 static void match_call(struct expression *expr)
65 char *fn_name;
66 int len;
68 if (!in_w)
69 return;
71 fn_name = expr_to_var(expr->fn);
72 if (!fn_name)
73 goto free;
74 len = strlen(fn_name);
75 if (fn_name[len - 1] == 'A' && !allowed_func(fn_name)) {
76 sm_warning("WtoA call '%s()'", fn_name);
78 free:
79 free_string(fn_name);
82 void check_wine_WtoA(int id)
84 if (option_project != PROJ_WINE)
85 return;
87 my_id = id;
88 add_hook(&match_function_def, FUNC_DEF_HOOK);
89 add_hook(&match_call, FUNCTION_CALL_HOOK);