From 5ff462a00073d673b7506d72d561f691dc661447 Mon Sep 17 00:00:00 2001 From: "sicking%bigfoot.com" Date: Sat, 18 Jan 2003 14:04:23 +0000 Subject: [PATCH] Bug 162115: Make nsCOMArray return nsDeriviedSafes to avoid bad addrefs/releases r=bz sr=alecf --- xpcom/ds/nsCOMArray.cpp | 2 +- xpcom/ds/nsCOMArray.h | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/xpcom/ds/nsCOMArray.cpp b/xpcom/ds/nsCOMArray.cpp index a645704eed85..185598bfdfa2 100644 --- a/xpcom/ds/nsCOMArray.cpp +++ b/xpcom/ds/nsCOMArray.cpp @@ -76,7 +76,7 @@ nsCOMArray_base::InsertObjectsAt(const nsCOMArray_base& aObjects, PRInt32 aIndex // need to addref all these PRInt32 count = aObjects.Count(); for (PRInt32 i = 0; i < count; ++i) { - NS_IF_ADDREF(aObjects.ObjectAt(i)); + NS_IF_ADDREF(NS_STATIC_CAST(nsISupports*, aObjects.mArray[i])); } } return result; diff --git a/xpcom/ds/nsCOMArray.h b/xpcom/ds/nsCOMArray.h index ba9b46aaeccf..c69eb72b471c 100644 --- a/xpcom/ds/nsCOMArray.h +++ b/xpcom/ds/nsCOMArray.h @@ -41,6 +41,7 @@ #include "nsVoidArray.h" #include "nsISupports.h" +#include "nsCOMPtr.h" // See below for the definition of nsCOMArray @@ -90,11 +91,11 @@ public: return mArray.Count(); } - nsISupports* ObjectAt(PRInt32 aIndex) const { - return NS_STATIC_CAST(nsISupports*, mArray.ElementAt(aIndex)); + nsDerivedSafe* ObjectAt(PRInt32 aIndex) const { + return NS_REINTERPRET_CAST(nsDerivedSafe*, mArray.ElementAt(aIndex)); } - nsISupports* operator[](PRInt32 aIndex) const { + nsDerivedSafe* operator[](PRInt32 aIndex) const { return ObjectAt(aIndex); } @@ -139,12 +140,12 @@ class nsCOMArray : public nsCOMArray_base ~nsCOMArray() {} // these do NOT refcount on the way out, for speed - T* ObjectAt(PRInt32 aIndex) const { - return NS_STATIC_CAST(T*,nsCOMArray_base::ObjectAt(aIndex)); + nsDerivedSafe* ObjectAt(PRInt32 aIndex) const { + return NS_REINTERPRET_CAST(nsDerivedSafe*,nsCOMArray_base::ObjectAt(aIndex)); } // indexing operator for syntactic sugar - T* operator[](PRInt32 aIndex) const { + nsDerivedSafe* operator[](PRInt32 aIndex) const { return ObjectAt(aIndex); }