diff options
-rw-r--r-- | src/corelib/tools/qvarlengtharray.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 90b10a3ed1..0c5b61d68a 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -252,12 +252,17 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray<T, Prealloc>::realloc(int asize, int a const int copySize = qMin(asize, osize); if (aalloc != a) { - T* newPtr = reinterpret_cast<T *>(malloc(aalloc * sizeof(T))); - Q_CHECK_PTR(newPtr); // could throw - // by design: in case of QT_NO_EXCEPTIONS malloc must not fail or it crashes here - ptr = newPtr; + if (aalloc > Prealloc) { + T* newPtr = reinterpret_cast<T *>(malloc(aalloc * sizeof(T))); + Q_CHECK_PTR(newPtr); // could throw + // by design: in case of QT_NO_EXCEPTIONS malloc must not fail or it crashes here + ptr = newPtr; + a = aalloc; + } else { + ptr = reinterpret_cast<T *>(array); + a = Prealloc; + } s = 0; - a = aalloc; if (QTypeInfo<T>::isStatic) { QT_TRY { // copy all the old elements |