From 932310909a276a43d8b925e07c97d723c2f340f6 Mon Sep 17 00:00:00 2001 From: "sicking%bigfoot.com" Date: Wed, 2 Nov 2005 16:05:15 +0000 Subject: [PATCH] Bug 225507: Implement nsCOMArray::SafeObjectAt for out-of-bounds safe access. r=bryner sr=alecf --- xpcom/glue/nsCOMArray.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xpcom/glue/nsCOMArray.h b/xpcom/glue/nsCOMArray.h index d34a48727a17..98c2a08288e2 100644 --- a/xpcom/glue/nsCOMArray.h +++ b/xpcom/glue/nsCOMArray.h @@ -100,6 +100,10 @@ public: return NS_STATIC_CAST(nsISupports*, mArray.ElementAt(aIndex)); } + nsISupports* SafeObjectAt(PRInt32 aIndex) const { + return NS_STATIC_CAST(nsISupports*, mArray.SafeElementAt(aIndex)); + } + nsISupports* operator[](PRInt32 aIndex) const { return ObjectAt(aIndex); } @@ -149,6 +153,11 @@ class nsCOMArray : public nsCOMArray_base return NS_STATIC_CAST(T*,nsCOMArray_base::ObjectAt(aIndex)); } + // these do NOT refcount on the way out, for speed + T* SafeObjectAt(PRInt32 aIndex) const { + return NS_STATIC_CAST(T*,nsCOMArray_base::SafeObjectAt(aIndex)); + } + // indexing operator for syntactic sugar T* operator[](PRInt32 aIndex) const { return ObjectAt(aIndex);