[PATCH] wininet: restructure for better return checking
Marcus Meissner
marcus at jet.franken.de
Mon Mar 3 12:23:24 CST 2008
Hi,
Coverity spotted some potential lpwhh NULL usage
after NULL checking.
I restructured the code a bit to check lpwhh
earlier and return at that time. Also removed a
unnecessary cast.
CIao, Marcus
---
dlls/wininet/internet.c | 24 ++++++++++++++++--------
1 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c
index c0709e6..4284dc3 100644
--- a/dlls/wininet/internet.c
+++ b/dlls/wininet/internet.c
@@ -1685,11 +1685,16 @@ BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
lpwh = WININET_GetObject( hFile );
+ if (!lpwh) {
+ WARN("Invalid handle\n");
+ SetLastError(ERROR_INVALID_HANDLE);
+ return FALSE;
+ }
- if(lpwh && lpwh->vtbl->WriteFile) {
+ if(lpwh->vtbl->WriteFile) {
retval = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
}else {
- WARN("Invalid handle\n");
+ WARN("No Writefile method.\n");
SetLastError(ERROR_INVALID_HANDLE);
retval = FALSE;
}
@@ -1856,7 +1861,7 @@ BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOu
return FALSE;
}
- lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
+ lpwh = WININET_GetObject( hFile );
if (!lpwh)
{
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
@@ -1951,7 +1956,7 @@ static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD d
TRACE("(%p, 0x%08x, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
- lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
+ lpwhh = WININET_GetObject( hInternet );
switch (dwOption)
{
@@ -2455,7 +2460,12 @@ BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
- if(lpwhh && lpwhh->vtbl->SetOption) {
+ if (!lpwhh) {
+ SetLastError(ERROR_INVALID_HANDLE);
+ return FALSE;
+ }
+
+ if(lpwhh->vtbl->SetOption) {
DWORD res;
res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
@@ -2560,9 +2570,7 @@ BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
break;
}
- if(lpwhh)
- WININET_Release( lpwhh );
-
+ WININET_Release( lpwhh );
return ret;
}
--
1.5.2.4
More information about the wine-patches
mailing list