Slightly safer and neater fix for strict aliasing bug 351231 r+sr=dbaron

This commit is contained in:
neil@parkwaycc.co.uk 2007-03-23 13:26:20 -07:00
parent 84b4bbf9fe
commit 417d5864d4
2 changed files with 56 additions and 56 deletions

View File

@ -92,64 +92,64 @@ nsCOMPtr_base::assign_with_AddRef( nsISupports* rawPtr )
void
nsCOMPtr_base::assign_from_qi( const nsQueryInterface qi, const nsIID& iid )
{
union { nsISupports *mSupports; void *mVoid; } newRawPtr;
if ( NS_FAILED( qi(iid, &newRawPtr.mVoid) ) )
newRawPtr.mSupports = 0;
assign_assuming_AddRef(newRawPtr.mSupports);
void* newRawPtr;
if ( NS_FAILED( qi(iid, &newRawPtr) ) )
newRawPtr = 0;
assign_assuming_AddRef(NS_STATIC_CAST(nsISupports*, newRawPtr));
}
void
nsCOMPtr_base::assign_from_qi_with_error( const nsQueryInterfaceWithError& qi, const nsIID& iid )
{
union { nsISupports* mSupports; void *mVoid; } newRawPtr;
if ( NS_FAILED( qi(iid, &newRawPtr.mVoid) ) )
newRawPtr.mSupports = 0;
assign_assuming_AddRef(newRawPtr.mSupports);
void* newRawPtr;
if ( NS_FAILED( qi(iid, &newRawPtr) ) )
newRawPtr = 0;
assign_assuming_AddRef(NS_STATIC_CAST(nsISupports*, newRawPtr));
}
void
nsCOMPtr_base::assign_from_gs_cid( const nsGetServiceByCID gs, const nsIID& iid )
{
union { nsISupports* mSupports; void *mVoid; } newRawPtr;
if ( NS_FAILED( gs(iid, &newRawPtr.mVoid) ) )
newRawPtr.mSupports = 0;
assign_assuming_AddRef(newRawPtr.mSupports);
void* newRawPtr;
if ( NS_FAILED( gs(iid, &newRawPtr) ) )
newRawPtr = 0;
assign_assuming_AddRef(NS_STATIC_CAST(nsISupports*, newRawPtr));
}
void
nsCOMPtr_base::assign_from_gs_cid_with_error( const nsGetServiceByCIDWithError& gs, const nsIID& iid )
{
union { nsISupports* mSupports; void *mVoid; } newRawPtr;
if ( NS_FAILED( gs(iid, &newRawPtr.mVoid) ) )
newRawPtr.mSupports = 0;
assign_assuming_AddRef(newRawPtr.mSupports);
void* newRawPtr;
if ( NS_FAILED( gs(iid, &newRawPtr) ) )
newRawPtr = 0;
assign_assuming_AddRef(NS_STATIC_CAST(nsISupports*, newRawPtr));
}
void
nsCOMPtr_base::assign_from_gs_contractid( const nsGetServiceByContractID gs, const nsIID& iid )
{
union { nsISupports* mSupports; void *mVoid; } newRawPtr;
if ( NS_FAILED( gs(iid, &newRawPtr.mVoid) ) )
newRawPtr.mSupports = 0;
assign_assuming_AddRef(newRawPtr.mSupports);
void* newRawPtr;
if ( NS_FAILED( gs(iid, &newRawPtr) ) )
newRawPtr = 0;
assign_assuming_AddRef(NS_STATIC_CAST(nsISupports*, newRawPtr));
}
void
nsCOMPtr_base::assign_from_gs_contractid_with_error( const nsGetServiceByContractIDWithError& gs, const nsIID& iid )
{
union { nsISupports* mSupports; void *mVoid; } newRawPtr;
if ( NS_FAILED( gs(iid, &newRawPtr.mVoid) ) )
newRawPtr.mSupports = 0;
assign_assuming_AddRef(newRawPtr.mSupports);
void* newRawPtr;
if ( NS_FAILED( gs(iid, &newRawPtr) ) )
newRawPtr = 0;
assign_assuming_AddRef(NS_STATIC_CAST(nsISupports*, newRawPtr));
}
void
nsCOMPtr_base::assign_from_helper( const nsCOMPtr_helper& helper, const nsIID& iid )
{
union { nsISupports* mSupports; void *mVoid; } newRawPtr;
if ( NS_FAILED( helper(iid, &newRawPtr.mVoid) ) )
newRawPtr.mSupports = 0;
assign_assuming_AddRef(newRawPtr.mSupports);
void* newRawPtr;
if ( NS_FAILED( helper(iid, &newRawPtr) ) )
newRawPtr = 0;
assign_assuming_AddRef(NS_STATIC_CAST(nsISupports*, newRawPtr));
}
void**

View File

@ -1240,70 +1240,70 @@ template <class T>
void
nsCOMPtr<T>::assign_from_qi( const nsQueryInterface qi, const nsIID& aIID )
{
union { T* mT; void *mVoid; } newRawPtr;
if ( NS_FAILED( qi(aIID, &newRawPtr.mVoid) ) )
newRawPtr.mT = 0;
assign_assuming_AddRef(newRawPtr.mT);
void* newRawPtr;
if ( NS_FAILED( qi(aIID, &newRawPtr) ) )
newRawPtr = 0;
assign_assuming_AddRef(NS_STATIC_CAST(T*, newRawPtr));
}
template <class T>
void
nsCOMPtr<T>::assign_from_qi_with_error( const nsQueryInterfaceWithError& qi, const nsIID& aIID )
{
union { T* mT; void *mVoid; } newRawPtr;
if ( NS_FAILED( qi(aIID, &newRawPtr.mVoid) ) )
newRawPtr.mT = 0;
assign_assuming_AddRef(newRawPtr.mT);
void* newRawPtr;
if ( NS_FAILED( qi(aIID, &newRawPtr) ) )
newRawPtr = 0;
assign_assuming_AddRef(NS_STATIC_CAST(T*, newRawPtr));
}
template <class T>
void
nsCOMPtr<T>::assign_from_gs_cid( const nsGetServiceByCID gs, const nsIID& aIID )
{
union { T* mT; void *mVoid; } newRawPtr;
if ( NS_FAILED( gs(aIID, &newRawPtr.mVoid) ) )
newRawPtr.mT = 0;
assign_assuming_AddRef(newRawPtr.mT);
void* newRawPtr;
if ( NS_FAILED( gs(aIID, &newRawPtr) ) )
newRawPtr = 0;
assign_assuming_AddRef(NS_STATIC_CAST(T*, newRawPtr));
}
template <class T>
void
nsCOMPtr<T>::assign_from_gs_cid_with_error( const nsGetServiceByCIDWithError& gs, const nsIID& aIID )
{
union { T* mT; void *mVoid; } newRawPtr;
if ( NS_FAILED( gs(aIID, &newRawPtr.mVoid) ) )
newRawPtr.mT = 0;
assign_assuming_AddRef(newRawPtr.mT);
void* newRawPtr;
if ( NS_FAILED( gs(aIID, &newRawPtr) ) )
newRawPtr = 0;
assign_assuming_AddRef(NS_STATIC_CAST(T*, newRawPtr));
}
template <class T>
void
nsCOMPtr<T>::assign_from_gs_contractid( const nsGetServiceByContractID gs, const nsIID& aIID )
{
union { T* mT; void *mVoid; } newRawPtr;
if ( NS_FAILED( gs(aIID, &newRawPtr.mVoid) ) )
newRawPtr.mT = 0;
assign_assuming_AddRef(newRawPtr.mT);
void* newRawPtr;
if ( NS_FAILED( gs(aIID, &newRawPtr) ) )
newRawPtr = 0;
assign_assuming_AddRef(NS_STATIC_CAST(T*, newRawPtr));
}
template <class T>
void
nsCOMPtr<T>::assign_from_gs_contractid_with_error( const nsGetServiceByContractIDWithError& gs, const nsIID& aIID )
{
union { T* mT; void *mVoid; } newRawPtr;
if ( NS_FAILED( gs(aIID, &newRawPtr.mVoid) ) )
newRawPtr.mT = 0;
assign_assuming_AddRef(newRawPtr.mT);
void* newRawPtr;
if ( NS_FAILED( gs(aIID, &newRawPtr) ) )
newRawPtr = 0;
assign_assuming_AddRef(NS_STATIC_CAST(T*, newRawPtr));
}
template <class T>
void
nsCOMPtr<T>::assign_from_helper( const nsCOMPtr_helper& helper, const nsIID& aIID )
{
union { T* mT; void *mVoid; } newRawPtr;
if ( NS_FAILED( helper(aIID, &newRawPtr.mVoid) ) )
newRawPtr.mT = 0;
assign_assuming_AddRef(newRawPtr.mT);
void* newRawPtr;
if ( NS_FAILED( helper(aIID, &newRawPtr) ) )
newRawPtr = 0;
assign_assuming_AddRef(NS_STATIC_CAST(T*, newRawPtr));
}
template <class T>