mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 1473804: Don't lie to AutoTArray::EnsureCapacity. r=erahm
Differential Revision: https://phabricator.services.mozilla.com/D1995 MozReview-Commit-ID: 350uWaD49tS
This commit is contained in:
parent
10c9edc486
commit
6b1dec4b78
@ -461,9 +461,8 @@ nsTArray_base<Alloc, Copy>::SwapArrayElements(nsTArray_base<Allocator,
|
||||
// job for AutoTArray! (One of the two arrays we're swapping is using an
|
||||
// auto buffer, so we're likely not allocating a lot of space here. But one
|
||||
// could, in theory, allocate a huge AutoTArray on the heap.)
|
||||
AutoTArray<nsTArray_Impl<uint8_t, ActualAlloc>, 64> temp;
|
||||
if (!ActualAlloc::Successful(temp.template EnsureCapacity<ActualAlloc>(smallerLength,
|
||||
aElemSize))) {
|
||||
AutoTArray<uint8_t, 64 * sizeof(void*)> temp;
|
||||
if (!ActualAlloc::Successful(temp.template EnsureCapacity<ActualAlloc>(smallerLength * aElemSize, sizeof(uint8_t)))) {
|
||||
return ActualAlloc::FailureResult();
|
||||
}
|
||||
|
||||
|
@ -1086,4 +1086,29 @@ TEST(TArray, test_comparator_objects) {
|
||||
ASSERT_TRUE(TestCompareMethods([] (int aLeft, int aRight) { return aLeft - aRight; }));
|
||||
}
|
||||
|
||||
struct Big
|
||||
{
|
||||
uint64_t size[40] = {};
|
||||
};
|
||||
|
||||
TEST(TArray, test_AutoTArray_SwapElements) {
|
||||
AutoTArray<Big, 40> oneArray;
|
||||
AutoTArray<Big, 40> another;
|
||||
|
||||
for (size_t i = 0; i < 8; ++i) {
|
||||
oneArray.AppendElement(Big());
|
||||
}
|
||||
oneArray[0].size[10] = 1;
|
||||
for (size_t i = 0; i < 9; ++i) {
|
||||
another.AppendElement(Big());
|
||||
}
|
||||
oneArray.SwapElements(another);
|
||||
|
||||
ASSERT_EQ(oneArray.Length(), 9u);
|
||||
ASSERT_EQ(another.Length(), 8u);
|
||||
|
||||
ASSERT_EQ(oneArray[0].size[10], 0u);
|
||||
ASSERT_EQ(another[0].size[10], 1u);
|
||||
}
|
||||
|
||||
} // namespace TestTArray
|
||||
|
Loading…
Reference in New Issue
Block a user