sm_info: fix formatting
[smatch.git] / check_wine_WtoA.c
blobcd84d8e3ff2bf52b674ab182a22acbffd856a2ed
1 /*
2 * sparse/check_template.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
11 * Idea from Michael Stefaniuc and Vincent BĂ©ron's earlier WtoA
12 * check.
14 * Apparently when you are coding WINE, you are not allowed to call
15 * functions that end in capital 'A' from functions that end in
16 * capital 'W'
20 #include "smatch.h"
22 static int my_id;
24 static int in_w = 0;
26 static void match_function_def(struct symbol *sym)
28 char *func = get_function();
29 int len = strlen(func);
31 if (func[len - 1] == 'W' && len > 2 && func[len - 2] != 'A' )
32 in_w = 1;
33 else
34 in_w = 0;
37 static int allowed_func(const char *fn)
39 if (!strcmp("lstrcatA", fn))
40 return 1;
41 if (!strcmp("lstrcpyA", fn))
42 return 1;
43 if (!strcmp("lstrcpynA", fn))
44 return 1;
45 if (!strcmp("lstrlenA", fn))
46 return 1;
47 return 0;
50 static void match_call(struct expression *expr)
52 char *fn_name;
53 int len;
55 if (!in_w)
56 return;
58 fn_name = get_variable_from_expr(expr->fn, NULL);
59 if (!fn_name)
60 goto free;
61 len = strlen(fn_name);
62 if (fn_name[len - 1] == 'A' && !allowed_func(fn_name)) {
63 sm_msg("warn: WtoA call %s()", fn_name);
65 free:
66 free_string(fn_name);
69 void check_wine_WtoA(int id)
71 if (option_project != PROJ_WINE)
72 return;
74 my_id = id;
75 add_hook(&match_function_def, FUNC_DEF_HOOK);
76 add_hook(&match_call, FUNCTION_CALL_HOOK);