2 * sparse/check_wine_filehandles.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 * In wine you aren't allowed to compare file handles with 0,
12 * only with INVALID_HANDLE_VALUE.
25 * "(?:CreateFile|CreateMailslot|CreateNamedPipe|FindFirstFile(?:Ex)?|OpenConsole|SetupOpenInfFile|socket)[AW]?"
28 static const char *filehandle_funcs
[] = {
40 static void match_returns_handle(const char *fn
, struct expression
*expr
,
43 char *left_name
= NULL
;
44 struct symbol
*left_sym
;
46 left_name
= get_variable_from_expr(expr
->left
, &left_sym
);
47 if (!left_name
|| !left_sym
)
49 set_state_expr(my_id
, expr
->left
, &filehandle
);
51 free_string(left_name
);
54 static void match_condition(struct expression
*expr
)
56 if (expr
->type
== EXPR_ASSIGNMENT
)
57 match_condition(expr
->left
);
59 if (get_state_expr(my_id
, expr
) == &filehandle
) {
62 name
= get_variable_from_expr(expr
, NULL
);
63 sm_msg("error: comparing a filehandle against zero '%s'", name
);
64 set_state_expr(my_id
, expr
, &oktocheck
);
69 void check_wine_filehandles(int id
)
73 if (option_project
!= PROJ_WINE
)
77 set_default_state(my_id
, &oktocheck
);
78 for(i
= 0; filehandle_funcs
[i
]; i
++) {
79 add_function_assign_hook(filehandle_funcs
[i
],
80 &match_returns_handle
, NULL
);
82 add_hook(&match_condition
, CONDITION_HOOK
);