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.
24 * "(?:CreateFile|CreateMailslot|CreateNamedPipe|FindFirstFile(?:Ex)?|OpenConsole|SetupOpenInfFile|socket)[AW]?"
27 static const char *filehandle_funcs
[] = {
39 static void ok_to_use(struct sm_state
*sm
)
41 if (sm
->state
!= &oktocheck
)
42 set_state(my_id
, sm
->name
, sm
->sym
, &oktocheck
);
45 static void match_returns_handle(const char *fn
, struct expression
*expr
,
48 char *left_name
= NULL
;
49 struct symbol
*left_sym
;
51 left_name
= get_variable_from_expr(expr
->left
, &left_sym
);
52 if (!left_name
|| !left_sym
)
54 set_state_expr(my_id
, expr
->left
, &filehandle
);
56 free_string(left_name
);
59 static void match_condition(struct expression
*expr
)
61 if (expr
->type
== EXPR_ASSIGNMENT
)
62 match_condition(expr
->left
);
64 if (get_state_expr(my_id
, expr
) == &filehandle
) {
67 name
= get_variable_from_expr(expr
, NULL
);
68 sm_msg("error: comparing a filehandle against zero '%s'", name
);
69 set_state_expr(my_id
, expr
, &oktocheck
);
74 void check_wine_filehandles(int id
)
78 if (option_project
!= PROJ_WINE
)
82 for (i
= 0; filehandle_funcs
[i
]; i
++) {
83 add_function_assign_hook(filehandle_funcs
[i
],
84 &match_returns_handle
, NULL
);
86 add_hook(&match_condition
, CONDITION_HOOK
);
87 add_modification_hook(my_id
, ok_to_use
);