Bug #107369: Check nNewSize=0 in AllocateSpace() and add current size to AllocateSpace() calls. r=bienvenu,sr=sspitzer.

This commit is contained in:
cavin%netscape.com 2001-11-15 00:06:37 +00:00
parent fa6a218016
commit fc1fd71921
3 changed files with 5 additions and 4 deletions

View File

@ -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];

View File

@ -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;

View File

@ -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