Detlef Riekenberg : shlwapi: Fix broken NULL checks (with tests).

Alexandre Julliard julliard at winehq.org
Mon Apr 19 11:51:18 CDT 2010


Module: wine
Branch: master
Commit: a9ac4a119a5ee94896298532c602713389b7a5c9
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=a9ac4a119a5ee94896298532c602713389b7a5c9

Author: Detlef Riekenberg <wine.dev at web.de>
Date:   Mon Apr 19 00:45:19 2010 +0200

shlwapi: Fix broken NULL checks (with tests).

---

 dlls/shlwapi/tests/thread.c |   16 +++++++++++++++-
 dlls/shlwapi/thread.c       |    8 ++++----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/dlls/shlwapi/tests/thread.c b/dlls/shlwapi/tests/thread.c
index 90e87f5..ea89424 100644
--- a/dlls/shlwapi/tests/thread.c
+++ b/dlls/shlwapi/tests/thread.c
@@ -110,6 +110,11 @@ static void test_SHSetThreadRef(void)
         return;
     }
 
+    /* start with a clean state */
+    hr = pSHSetThreadRef(NULL);
+    ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
+
+    /* build and set out object */
     init_threadref(&ref, &refcount);
     AddRef_called = 0;
     refcount = 1;
@@ -118,7 +123,7 @@ static void test_SHSetThreadRef(void)
         "got 0x%x with %d, %d (expected S_OK with 1, 0)\n",
         hr, refcount, AddRef_called);
 
-    /* Read back IUnkonwn */
+    /* read back our object */
     AddRef_called = 0;
     refcount = 1;
     punk = NULL;
@@ -127,6 +132,15 @@ static void test_SHSetThreadRef(void)
         "got 0x%x and %p with %d, %d (expected S_OK and %p with 2, 1)\n",
         hr, punk, refcount, AddRef_called, &ref);
 
+    /* clear the onject pointer */
+    hr = pSHSetThreadRef(NULL);
+    ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
+
+    /* verify, that our object is no longer known as ThreadRef */
+    hr = pSHGetThreadRef(&punk);
+    ok( (hr == E_NOINTERFACE) && (punk == NULL),
+        "got 0x%x and %p (expected E_NOINTERFACE and NULL)\n", hr, punk);
+
 }
 
 START_TEST(thread)
diff --git a/dlls/shlwapi/thread.c b/dlls/shlwapi/thread.c
index cfe6615..fd9e4ba 100644
--- a/dlls/shlwapi/thread.c
+++ b/dlls/shlwapi/thread.c
@@ -131,13 +131,13 @@ typedef struct tagSHLWAPI_THREAD_INFO
  *
  * RETURNS
  *   Success: S_OK. lppUnknown is set to the object reference.
- *   Failure: E_NOINTERFACE, if an error occurs or lppUnknown is NULL.
+ *   Failure: E_NOINTERFACE, if an error occurs or no object is set
  */
 HRESULT WINAPI SHGetThreadRef(IUnknown **lppUnknown)
 {
   TRACE("(%p)\n", lppUnknown);
 
-  if (!lppUnknown || SHLWAPI_ThreadRef_index == TLS_OUT_OF_INDEXES)
+  if (SHLWAPI_ThreadRef_index == TLS_OUT_OF_INDEXES)
     return E_NOINTERFACE;
 
   *lppUnknown = TlsGetValue(SHLWAPI_ThreadRef_index);
@@ -159,13 +159,13 @@ HRESULT WINAPI SHGetThreadRef(IUnknown **lppUnknown)
  *
  * RETURNS
  *   Success: S_OK. lpUnknown is stored and can be retrieved by SHGetThreadRef()
- *   Failure: E_NOINTERFACE, if an error occurs or lpUnknown is NULL.
+ *   Failure: E_NOINTERFACE, if an error occurs
  */
 HRESULT WINAPI SHSetThreadRef(IUnknown *lpUnknown)
 {
   TRACE("(%p)\n", lpUnknown);
 
-  if (!lpUnknown || SHLWAPI_ThreadRef_index  == TLS_OUT_OF_INDEXES)
+  if (SHLWAPI_ThreadRef_index == TLS_OUT_OF_INDEXES)
     return E_NOINTERFACE;
 
   TlsSetValue(SHLWAPI_ThreadRef_index, lpUnknown);




More information about the wine-cvs mailing list