smatch.c: use strncpy() instead of strcpy()
[smatch.git] / check_wine_WtoA.c
blobe2cc1f796924067c97d647aaac856831af5d81f1
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;
31 if (!func) {
32 in_w = 0;
33 return;
35 len = strlen(func);
36 if (func[len - 1] == 'W' && len > 2 && func[len - 2] != 'A' )
37 in_w = 1;
38 else
39 in_w = 0;
42 static int allowed_func(const char *fn)
44 if (!strcmp("lstrcatA", fn))
45 return 1;
46 if (!strcmp("lstrcpyA", fn))
47 return 1;
48 if (!strcmp("lstrcpynA", fn))
49 return 1;
50 if (!strcmp("lstrlenA", fn))
51 return 1;
52 return 0;
55 static void match_call(struct expression *expr)
57 char *fn_name;
58 int len;
60 if (!in_w)
61 return;
63 fn_name = get_variable_from_expr(expr->fn, NULL);
64 if (!fn_name)
65 goto free;
66 len = strlen(fn_name);
67 if (fn_name[len - 1] == 'A' && !allowed_func(fn_name)) {
68 sm_msg("warn: WtoA call %s()", fn_name);
70 free:
71 free_string(fn_name);
74 void check_wine_WtoA(int id)
76 if (option_project != PROJ_WINE)
77 return;
79 my_id = id;
80 add_hook(&match_function_def, FUNC_DEF_HOOK);
81 add_hook(&match_call, FUNCTION_CALL_HOOK);