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(const char *name
, struct symbol
*sym
, struct expression
*expr
, void *unused
)
41 delete_state(my_id
, name
, sym
);
44 static void match_returns_handle(const char *fn
, struct expression
*expr
,
47 char *left_name
= NULL
;
48 struct symbol
*left_sym
;
50 left_name
= get_variable_from_expr(expr
->left
, &left_sym
);
51 if (!left_name
|| !left_sym
)
53 set_state_expr(my_id
, expr
->left
, &filehandle
);
54 add_modification_hook_expr(my_id
, expr
->left
, ok_to_use
, NULL
);
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
);