PODArray assign empty array fix

This commit is contained in:
Maksim Kita 2022-08-11 16:26:41 +02:00
parent c746dcd644
commit f9326b00c8
2 changed files with 31 additions and 3 deletions

View File

@ -703,10 +703,9 @@ public:
size_t bytes_to_copy = this->byte_size(required_capacity);
if (bytes_to_copy)
{
memcpy(this->c_start, reinterpret_cast<const void *>(&*from_begin), bytes_to_copy);
this->c_end = this->c_start + bytes_to_copy;
}
this->c_end = this->c_start + bytes_to_copy;
}
// ISO C++ has strict ambiguity rules, thus we cannot apply TAllocatorParams here.

View File

@ -484,6 +484,35 @@ TEST(Common, PODArrayInsertFromItself)
}
}
TEST(Common, PODArrayAssign)
{
{
PaddedPODArray<UInt64> array;
array.push_back(1);
array.push_back(2);
array.assign({1, 2, 3});
ASSERT_EQ(array.size(), 3);
ASSERT_EQ(array, PaddedPODArray<UInt64>({1, 2, 3}));
}
{
PaddedPODArray<UInt64> array;
array.push_back(1);
array.push_back(2);
array.assign({});
ASSERT_TRUE(array.empty());
}
{
PaddedPODArray<UInt64> array;
array.assign({});
ASSERT_TRUE(array.empty());
}
}
TEST(Common, PODNoOverallocation)
{
/// Check that PaddedPODArray allocates for smaller number of elements than the power of two due to padding.