COMMON: Fix inserting an array into itself under certain conditions

This commit is contained in:
Max Horn 2011-05-16 15:23:09 +02:00
parent a564a10e7f
commit 88319a727a
2 changed files with 32 additions and 1 deletions

View file

@ -293,9 +293,12 @@ protected:
if (n) {
const uint idx = pos - _storage;
T *oldStorage = _storage;
if (_size + n > _capacity) {
if (_size + n > _capacity || (_storage <= first && first <= _storage + _size) ) {
// If there is not enough space, allocate more and
// copy old elements over.
// Likewise, if this is a self-insert, we allocate new
// storage to avoid conflicts. This is not the most efficient
// way to ensure that, but probably the simplest on.
allocCapacity(roundUpCapacity(_size + n));
copy(oldStorage, oldStorage + idx, _storage);
pos = _storage + idx;