Bug 1415083 - Rearrange the declaration of objects to avoid stack-use-after-scope. r=froydnj
authorJames Cheng <jacheng@mozilla.com>
Tue, 07 Nov 2017 17:02:54 +0800
changeset 443922 1528ff0ed838f7079c3572e2dadc83dda6acbf8d
parent 443921 b72eaedcdfaa1154fb33e1638e4bd090375789ad
child 443923 1557f5e4e889f4f8cec8f598e42dd3e8c6d94cf6
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1415083
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1415083 - Rearrange the declaration of objects to avoid stack-use-after-scope. r=froydnj MozReview-Commit-ID: 7nMw1i10b7e
xpcom/tests/gtest/TestTArray.cpp
--- a/xpcom/tests/gtest/TestTArray.cpp
+++ b/xpcom/tests/gtest/TestTArray.cpp
@@ -139,22 +139,22 @@ TEST(TArray, AssignmentOperatorSelfAssig
   array = array;
   ASSERT_EQ(DummyArray(), array);
   array = Move(array);
   ASSERT_EQ(DummyArray(), array);
 }
 
 TEST(TArray, CopyOverlappingForwards)
 {
-  nsTArray<Movable> array;
   const size_t rangeLength = 8;
   const size_t initialLength = 2 * rangeLength;
+  uint32_t destructionCounters[initialLength];
+  nsTArray<Movable> array;
   array.AppendElements(initialLength);
 
-  uint32_t destructionCounters[initialLength];
   for (uint32_t i = 0; i < initialLength; ++i) {
     destructionCounters[i] = 0;
   }
   for (uint32_t i = 0; i < initialLength; ++i) {
     array[i].mDestructionCounter = &destructionCounters[i];
   }
 
   const size_t removedLength = rangeLength / 2;
@@ -167,33 +167,33 @@ TEST(TArray, CopyOverlappingForwards)
     ASSERT_EQ(destructionCounters[i], 0u);
   }
 }
 
 // The code to copy overlapping regions had a bug in that it wouldn't correctly
 // destroy all over the source elements being copied.
 TEST(TArray, CopyOverlappingBackwards)
 {
-  nsTArray<Copyable> array;
   const size_t rangeLength = 8;
   const size_t initialLength = 2 * rangeLength;
+  uint32_t destructionCounters[initialLength];
+  nsTArray<Copyable> array;
   array.SetCapacity(3 * rangeLength);
   array.AppendElements(initialLength);
   // To tickle the bug, we need to copy a source region:
   //
   //   ..XXXXX..
   //
   // such that it overlaps the destination region:
   //
   //   ....XXXXX
   //
   // so we are forced to copy back-to-front to ensure correct behavior.
   // The easiest way to do that is to call InsertElementsAt, which will force
   // the desired kind of shift.
-  uint32_t destructionCounters[initialLength];
   for (uint32_t i = 0; i < initialLength; ++i) {
     destructionCounters[i] = 0;
   }
   for (uint32_t i = 0; i < initialLength; ++i) {
     array[i].mDestructionCounter = &destructionCounters[i];
   }
 
   array.InsertElementsAt(0, rangeLength);