shlwapi: Fix broken NULL checks (with tests).

This commit is contained in:
Detlef Riekenberg 2010-04-19 00:45:19 +02:00 committed by Alexandre Julliard
parent 324783ad09
commit a9ac4a119a
2 changed files with 19 additions and 5 deletions

View File

@ -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)

View File

@ -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);