From 3f519daa882c403c29d9f39ca88509d283358be0 Mon Sep 17 00:00:00 2001 From: James Cheng Date: Tue, 7 Nov 2017 17:02:54 +0800 Subject: [PATCH] Bug 1415083 - Rearrange the declaration of objects to avoid stack-use-after-scope. r=froydnj MozReview-Commit-ID: 7nMw1i10b7e --HG-- extra : rebase_source : ab23ef60ff800f522357037cacd02bf87d2960ee --- xpcom/tests/gtest/TestTArray.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xpcom/tests/gtest/TestTArray.cpp b/xpcom/tests/gtest/TestTArray.cpp index 10e33664f7c6..a737adb4212b 100644 --- a/xpcom/tests/gtest/TestTArray.cpp +++ b/xpcom/tests/gtest/TestTArray.cpp @@ -144,12 +144,12 @@ TEST(TArray, AssignmentOperatorSelfAssignment) TEST(TArray, CopyOverlappingForwards) { - nsTArray array; const size_t rangeLength = 8; const size_t initialLength = 2 * rangeLength; + uint32_t destructionCounters[initialLength]; + nsTArray array; array.AppendElements(initialLength); - uint32_t destructionCounters[initialLength]; for (uint32_t i = 0; i < initialLength; ++i) { destructionCounters[i] = 0; } @@ -172,9 +172,10 @@ TEST(TArray, CopyOverlappingForwards) // destroy all over the source elements being copied. TEST(TArray, CopyOverlappingBackwards) { - nsTArray array; const size_t rangeLength = 8; const size_t initialLength = 2 * rangeLength; + uint32_t destructionCounters[initialLength]; + nsTArray array; array.SetCapacity(3 * rangeLength); array.AppendElements(initialLength); // To tickle the bug, we need to copy a source region: @@ -188,7 +189,6 @@ TEST(TArray, CopyOverlappingBackwards) // 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; }