aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2011-05-16 15:23:09 +0200
committerMax Horn2011-05-16 15:23:17 +0200
commit88319a727a5adc4888ec17e5ee091e14ce176afd (patch)
tree1d59d4368371e23f42377083ce5ee75292d30867 /common
parenta564a10e7f0afd99d7f0936c5b3e1acce31875b7 (diff)
downloadscummvm-rg350-88319a727a5adc4888ec17e5ee091e14ce176afd.tar.gz
scummvm-rg350-88319a727a5adc4888ec17e5ee091e14ce176afd.tar.bz2
scummvm-rg350-88319a727a5adc4888ec17e5ee091e14ce176afd.zip
COMMON: Fix inserting an array into itself under certain conditions
Diffstat (limited to 'common')
-rw-r--r--common/array.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/common/array.h b/common/array.h
index 87325d60d3..7ab4a1b042 100644
--- a/common/array.h
+++ b/common/array.h
@@ -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;