From fc1fd71921fb71a6da05603c748d6b707029a917 Mon Sep 17 00:00:00 2001 From: "cavin%netscape.com" Date: Thu, 15 Nov 2001 00:06:37 +0000 Subject: [PATCH] Bug #107369: Check nNewSize=0 in AllocateSpace() and add current size to AllocateSpace() calls. r=bienvenu,sr=sspitzer. --- mailnews/base/src/nsMsgThreadedDBView.cpp | 6 +++--- mailnews/base/util/nsUInt32Array.h | 1 + mailnews/base/util/nsUint8Array.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/mailnews/base/src/nsMsgThreadedDBView.cpp b/mailnews/base/src/nsMsgThreadedDBView.cpp index fcd917787570..92e8036da233 100644 --- a/mailnews/base/src/nsMsgThreadedDBView.cpp +++ b/mailnews/base/src/nsMsgThreadedDBView.cpp @@ -166,9 +166,9 @@ nsresult nsMsgThreadedDBView::AddKeys(nsMsgKey *pKeys, PRInt32 *pFlags, const ch { PRInt32 numAdded = 0; // Allocate enough space first to avoid memory allocation/deallocation. - m_keys.AllocateSpace(numKeysToAdd); - m_flags.AllocateSpace(numKeysToAdd); - m_levels.AllocateSpace(numKeysToAdd); + m_keys.AllocateSpace(numKeysToAdd+m_keys.GetSize()); + m_flags.AllocateSpace(numKeysToAdd+m_flags.GetSize()); + m_levels.AllocateSpace(numKeysToAdd+m_levels.GetSize()); for (PRInt32 i = 0; i < numKeysToAdd; i++) { PRInt32 threadFlag = pFlags[i]; diff --git a/mailnews/base/util/nsUInt32Array.h b/mailnews/base/util/nsUInt32Array.h index 7e8930bafa5b..58b3b3fc59be 100644 --- a/mailnews/base/util/nsUInt32Array.h +++ b/mailnews/base/util/nsUInt32Array.h @@ -44,6 +44,7 @@ public: PRUint32 GetSize() const; PRBool SetSize(PRUint32 nNewSize, PRBool AdjustGrowth=PR_FALSE, PRUint32 nGrowBy = 0); PRBool AllocateSpace(PRUint32 nNewSize) { + if (nNewSize == 0) return PR_TRUE; PRUint32 saveSize = m_nSize; nsresult rv = SetSize(nNewSize); m_nSize = saveSize; diff --git a/mailnews/base/util/nsUint8Array.h b/mailnews/base/util/nsUint8Array.h index 291453c7a175..cd10fb340596 100644 --- a/mailnews/base/util/nsUint8Array.h +++ b/mailnews/base/util/nsUint8Array.h @@ -20,7 +20,7 @@ public: PRInt32 GetSize() const; PRInt32 GetUpperBound() const; void SetSize(PRInt32 nNewSize, PRInt32 nGrowBy = -1); - void AllocateSpace(PRUint32 nNewSize) { PRInt32 saveSize = m_nSize; SetSize(nNewSize); m_nSize = saveSize;}; + void AllocateSpace(PRUint32 nNewSize) { if (nNewSize == 0) return; PRInt32 saveSize = m_nSize; SetSize(nNewSize); m_nSize = saveSize;}; // Operations // Clean up