mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 17:56:04 +08:00
[cpp] Fixes #1159, illegal memory access in Vector.
This commit is contained in:
parent
d3e37284fc
commit
1c86d63941
@ -95,12 +95,19 @@ public:
|
|||||||
|
|
||||||
inline void add(const T &inValue) {
|
inline void add(const T &inValue) {
|
||||||
if (_size == _capacity) {
|
if (_size == _capacity) {
|
||||||
|
// inValue might reference an element in this buffer
|
||||||
|
// When we reallocate, the reference becomes invalid.
|
||||||
|
// We thus need to create a defensive copy before
|
||||||
|
// reallocating.
|
||||||
|
T valueCopy = inValue;
|
||||||
_capacity = (int) (_size * 1.75f);
|
_capacity = (int) (_size * 1.75f);
|
||||||
if (_capacity < 8) _capacity = 8;
|
if (_capacity < 8) _capacity = 8;
|
||||||
_buffer = Spine::SpineExtension::realloc<T>(_buffer, _capacity, __FILE__, __LINE__);
|
_buffer = spine::SpineExtension::realloc<T>(_buffer, _capacity, __FILE__, __LINE__);
|
||||||
}
|
construct(_buffer + _size++, valueCopy);
|
||||||
|
} else {
|
||||||
construct(_buffer + _size++, inValue);
|
construct(_buffer + _size++, inValue);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void addAll(Vector<T> &inValue) {
|
inline void addAll(Vector<T> &inValue) {
|
||||||
ensureCapacity(this->size() + inValue.size());
|
ensureCapacity(this->size() + inValue.size());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user