From 736d455dc3f6ca89ab9804f62376180d415e9330 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 git-svn-id: svn://10.0.0.236/trunk@136593 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/ds/nsCOMArray.cpp | 2 +- mozilla/xpcom/ds/nsCOMArray.h | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mozilla/xpcom/ds/nsCOMArray.cpp b/mozilla/xpcom/ds/nsCOMArray.cpp index a645704eed8..185598bfdfa 100644 --- a/mozilla/xpcom/ds/nsCOMArray.cpp +++ b/mozilla/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/mozilla/xpcom/ds/nsCOMArray.h b/mozilla/xpcom/ds/nsCOMArray.h index ba9b46aaecc..c69eb72b471 100644 --- a/mozilla/xpcom/ds/nsCOMArray.h +++ b/mozilla/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); }