[PATCH] wininet: restructure for better return checking
Marcus Meissner
marcus at jet.franken.de
Mon Mar 3 12:23:24 CST 2008
Hi,
rebased against last git.
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 184e7ed..ab3d80e 100644
--- a/dlls/wininet/internet.c
+++ b/dlls/wininet/internet.c
@@ -1686,11 +1686,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;
}
@@ -1830,7 +1835,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)
{
@@ -2334,7 +2339,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);
@@ -2439,9 +2449,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