Bug 504453 nsAttrAndChildArray::GrowBy worries coverity
authortimeless@mozdev.org
Wed, 22 Jul 2009 17:31:01 -0500
changeset 30570 c9ae720fb05d5805f26c1ed815008237495c08e2
parent 30569 df4bea349e364e9ef420f26db53c990c9d15306d
child 30571 f33661125d0809f8b6bc9dfe11f17865c4fcee3c
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs504453
milestone1.9.2a1pre
Bug 504453 nsAttrAndChildArray::GrowBy worries coverity r=sicking sr=sicking
content/base/src/nsAttrAndChildArray.cpp
--- a/content/base/src/nsAttrAndChildArray.cpp
+++ b/content/base/src/nsAttrAndChildArray.cpp
@@ -763,26 +763,24 @@ nsAttrAndChildArray::GrowBy(PRUint32 aGr
     do {
       size += ATTRCHILD_ARRAY_GROWSIZE;
     } while (size < minSize);
   }
   else {
     size = PR_BIT(PR_CeilingLog2(minSize));
   }
 
-  Impl* newImpl = static_cast<Impl*>
-                             (mImpl ? PR_Realloc(mImpl, size * sizeof(void*)) :
-              PR_Malloc(size * sizeof(void*)));
+  PRBool needToInitialize = !mImpl;
+  Impl* newImpl = static_cast<Impl*>(PR_Realloc(mImpl, size * sizeof(void*)));
   NS_ENSURE_TRUE(newImpl, PR_FALSE);
 
-  Impl* oldImpl = mImpl;
   mImpl = newImpl;
 
   // Set initial counts if we didn't have a buffer before
-  if (!oldImpl) {
+  if (needToInitialize) {
     mImpl->mMappedAttrs = nsnull;
     SetAttrSlotAndChildCount(0, 0);
   }
 
   mImpl->mBufferSize = size - NS_IMPL_EXTRA_SIZE;
 
   return PR_TRUE;
 }