11f5207b7SJohn Levon /*
21f5207b7SJohn Levon * Copyright (C) 2009 Dan Carpenter.
31f5207b7SJohn Levon *
41f5207b7SJohn Levon * This program is free software; you can redistribute it and/or
51f5207b7SJohn Levon * modify it under the terms of the GNU General Public License
61f5207b7SJohn Levon * as published by the Free Software Foundation; either version 2
71f5207b7SJohn Levon * of the License, or (at your option) any later version.
81f5207b7SJohn Levon *
91f5207b7SJohn Levon * This program is distributed in the hope that it will be useful,
101f5207b7SJohn Levon * but WITHOUT ANY WARRANTY; without even the implied warranty of
111f5207b7SJohn Levon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
121f5207b7SJohn Levon * GNU General Public License for more details.
131f5207b7SJohn Levon *
141f5207b7SJohn Levon * You should have received a copy of the GNU General Public License
151f5207b7SJohn Levon * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
161f5207b7SJohn Levon */
171f5207b7SJohn Levon
181f5207b7SJohn Levon /*
19*efe51d0cSJohn Levon * Idea from Michael Stefaniuc and Vincent Béron's earlier WtoA
201f5207b7SJohn Levon * check.
211f5207b7SJohn Levon *
221f5207b7SJohn Levon * Apparently when you are coding WINE, you are not allowed to call
231f5207b7SJohn Levon * functions that end in capital 'A' from functions that end in
241f5207b7SJohn Levon * capital 'W'
251f5207b7SJohn Levon *
261f5207b7SJohn Levon */
271f5207b7SJohn Levon
281f5207b7SJohn Levon #include "smatch.h"
291f5207b7SJohn Levon
301f5207b7SJohn Levon static int my_id;
311f5207b7SJohn Levon
321f5207b7SJohn Levon static int in_w = 0;
331f5207b7SJohn Levon
match_function_def(struct symbol * sym)341f5207b7SJohn Levon static void match_function_def(struct symbol *sym)
351f5207b7SJohn Levon {
361f5207b7SJohn Levon char *func = get_function();
371f5207b7SJohn Levon int len;
381f5207b7SJohn Levon
391f5207b7SJohn Levon if (!func) {
401f5207b7SJohn Levon in_w = 0;
411f5207b7SJohn Levon return;
421f5207b7SJohn Levon }
431f5207b7SJohn Levon len = strlen(func);
441f5207b7SJohn Levon if (func[len - 1] == 'W' && len > 2 && func[len - 2] != 'A' )
451f5207b7SJohn Levon in_w = 1;
461f5207b7SJohn Levon else
471f5207b7SJohn Levon in_w = 0;
481f5207b7SJohn Levon }
491f5207b7SJohn Levon
allowed_func(const char * fn)501f5207b7SJohn Levon static int allowed_func(const char *fn)
511f5207b7SJohn Levon {
521f5207b7SJohn Levon if (!strcmp("lstrcatA", fn))
531f5207b7SJohn Levon return 1;
541f5207b7SJohn Levon if (!strcmp("lstrcpyA", fn))
551f5207b7SJohn Levon return 1;
561f5207b7SJohn Levon if (!strcmp("lstrcpynA", fn))
571f5207b7SJohn Levon return 1;
581f5207b7SJohn Levon if (!strcmp("lstrlenA", fn))
591f5207b7SJohn Levon return 1;
601f5207b7SJohn Levon return 0;
611f5207b7SJohn Levon }
621f5207b7SJohn Levon
match_call(struct expression * expr)631f5207b7SJohn Levon static void match_call(struct expression *expr)
641f5207b7SJohn Levon {
651f5207b7SJohn Levon char *fn_name;
661f5207b7SJohn Levon int len;
671f5207b7SJohn Levon
681f5207b7SJohn Levon if (!in_w)
691f5207b7SJohn Levon return;
701f5207b7SJohn Levon
711f5207b7SJohn Levon fn_name = expr_to_var(expr->fn);
721f5207b7SJohn Levon if (!fn_name)
731f5207b7SJohn Levon goto free;
741f5207b7SJohn Levon len = strlen(fn_name);
751f5207b7SJohn Levon if (fn_name[len - 1] == 'A' && !allowed_func(fn_name)) {
761f5207b7SJohn Levon sm_warning("WtoA call '%s()'", fn_name);
771f5207b7SJohn Levon }
781f5207b7SJohn Levon free:
791f5207b7SJohn Levon free_string(fn_name);
801f5207b7SJohn Levon }
811f5207b7SJohn Levon
check_wine_WtoA(int id)821f5207b7SJohn Levon void check_wine_WtoA(int id)
831f5207b7SJohn Levon {
841f5207b7SJohn Levon if (option_project != PROJ_WINE)
851f5207b7SJohn Levon return;
861f5207b7SJohn Levon
871f5207b7SJohn Levon my_id = id;
881f5207b7SJohn Levon add_hook(&match_function_def, FUNC_DEF_HOOK);
891f5207b7SJohn Levon add_hook(&match_call, FUNCTION_CALL_HOOK);
901f5207b7SJohn Levon }
91