[PATCH] (RESUBMIT) wininet: restructure for better return checking
Marcus Meissner
marcus at jet.franken.de
Thu Mar 13 13:23:24 CDT 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 | 22 +++++++++++++++-------
1 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c
index d5fbbc1..5a055f7 100644
--- a/dlls/wininet/internet.c
+++ b/dlls/wininet/internet.c
@@ -1704,11 +1704,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;
}
@@ -1848,7 +1853,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)
{
@@ -2167,7 +2172,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);
@@ -2272,9 +2282,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