Don't compare file handles to NULL

Michael Stefaniuc mstefani at redhat.com
Wed Mar 7 16:32:05 CST 2007


Francois Gouget wrote:
> Jacek just sent a patch fixing the following bug:
> 
>      file = CreateFileW(fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY,NULL);
> -    if(file) {
> +    if(file != INVALID_HANDLE_VALUE) {
> 
> This looks like something that could be turned into a nice Smatch test.
> 
> Hint, hint...
You mean something like
http://people.redhat.com/mstefani/wine/smatch/scripts/file_handles.pl ?
It found following:
dlls/wininet/ftp.c 327 FTP_FtpPutFileW(54) Comparision of the file
handle 'hFile' with 0.
dlls/wininet/ftp.c 1353 FTP_FtpGetFileW(47) Comparision of the file
handle 'hFile' with 0.
dlls/rpcrt4/rpcss_np_client.c 92 RPCRT4_RpcssNPConnect(58) Comparision
of the file handle 'the_pipe' with 0.
dlls/dbghelp/msc.c 2311 pdb_fetch_file_info(21) Comparision of the file
handle 'hFile' with 0.
dlls/dbghelp/pe_module.c 145 pe_load_dbg_file(52) Comparision of the
file handle 'hFile' with 0.
programs/rpcss/np_server.c 393 RPCSS_NPConnect(57) Comparision of the
file handle 'the_pipe' with 0.

Most are false positives (non NULL check before CloseHandle()). 2-3 are
fishy at best.

bye
	michael
-- 
Michael Stefaniuc               Tel.: +49-711-96437-199
Sr. Network Engineer            Fax.: +49-711-96437-111
Red Hat GmbH                    Email: mstefani at redhat.com
Hauptstaetterstr. 58            http://www.redhat.de/
D-70178 Stuttgart



More information about the wine-devel mailing list