Now test pointer result _and_ error code on return from QueryInterface, as some implementations return garbage.

This commit is contained in:
scc%netscape.com 1999-01-16 02:37:22 +00:00
parent a81f4408e0
commit 36a41c6750
3 changed files with 18 additions and 9 deletions

View File

@ -427,8 +427,10 @@ class nsCOMPtr
*/
{
if ( aRawPtr )
aRawPtr->QueryInterface(T::IID(), NSCAP_REINTERPRET_CAST(void**, &mRawPtr));
// ...and |QueryInterface| does the |AddRef| for us
if ( !NS_SUCCEEDED(aRawPtr->QueryInterface(T::IID(), NSCAP_REINTERPRET_CAST(void**, &mRawPtr))) )
mRawPtr = 0; // ...in case they wrote |QueryInterface| wrong, and it returns an error _and_ a pointer
// ...and |QueryInterface| does the |AddRef| for us (if it returned a pointer)
}
nsCOMPtr( const nsDontAddRef<T>& aSmartPtr )
@ -471,7 +473,8 @@ class nsCOMPtr
{
T* rawPtr = 0;
if ( rhs )
rhs->QueryInterface(T::IID(), NSCAP_REINTERPRET_CAST(void**, &rawPtr));
if ( !NS_SUCCEEDED(rhs->QueryInterface(T::IID(), NSCAP_REINTERPRET_CAST(void**, &rawPtr))) )
rawPtr = 0;
if ( mIsAwaitingAddRef )
mIsAwaitingAddRef = 0;

View File

@ -427,8 +427,10 @@ class nsCOMPtr
*/
{
if ( aRawPtr )
aRawPtr->QueryInterface(T::IID(), NSCAP_REINTERPRET_CAST(void**, &mRawPtr));
// ...and |QueryInterface| does the |AddRef| for us
if ( !NS_SUCCEEDED(aRawPtr->QueryInterface(T::IID(), NSCAP_REINTERPRET_CAST(void**, &mRawPtr))) )
mRawPtr = 0; // ...in case they wrote |QueryInterface| wrong, and it returns an error _and_ a pointer
// ...and |QueryInterface| does the |AddRef| for us (if it returned a pointer)
}
nsCOMPtr( const nsDontAddRef<T>& aSmartPtr )
@ -471,7 +473,8 @@ class nsCOMPtr
{
T* rawPtr = 0;
if ( rhs )
rhs->QueryInterface(T::IID(), NSCAP_REINTERPRET_CAST(void**, &rawPtr));
if ( !NS_SUCCEEDED(rhs->QueryInterface(T::IID(), NSCAP_REINTERPRET_CAST(void**, &rawPtr))) )
rawPtr = 0;
if ( mIsAwaitingAddRef )
mIsAwaitingAddRef = 0;

View File

@ -427,8 +427,10 @@ class nsCOMPtr
*/
{
if ( aRawPtr )
aRawPtr->QueryInterface(T::IID(), NSCAP_REINTERPRET_CAST(void**, &mRawPtr));
// ...and |QueryInterface| does the |AddRef| for us
if ( !NS_SUCCEEDED(aRawPtr->QueryInterface(T::IID(), NSCAP_REINTERPRET_CAST(void**, &mRawPtr))) )
mRawPtr = 0; // ...in case they wrote |QueryInterface| wrong, and it returns an error _and_ a pointer
// ...and |QueryInterface| does the |AddRef| for us (if it returned a pointer)
}
nsCOMPtr( const nsDontAddRef<T>& aSmartPtr )
@ -471,7 +473,8 @@ class nsCOMPtr
{
T* rawPtr = 0;
if ( rhs )
rhs->QueryInterface(T::IID(), NSCAP_REINTERPRET_CAST(void**, &rawPtr));
if ( !NS_SUCCEEDED(rhs->QueryInterface(T::IID(), NSCAP_REINTERPRET_CAST(void**, &rawPtr))) )
rawPtr = 0;
if ( mIsAwaitingAddRef )
mIsAwaitingAddRef = 0;