From 680785d3353ab7274469c61be9cc750f22fcbd6d Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 30 May 2023 09:09:51 +0300 Subject: [PATCH] assume malloc() does not fail in QVarLengthArray::reallocData() even when malloc() is called with 0 as size it returns non-null pointer (some random garbage) Signed-off-by: Ivailo Monev --- src/core/tools/qvarlengtharray.h | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/core/tools/qvarlengtharray.h b/src/core/tools/qvarlengtharray.h index 92da5923a..c0eca94f2 100644 --- a/src/core/tools/qvarlengtharray.h +++ b/src/core/tools/qvarlengtharray.h @@ -206,23 +206,18 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray::reallocData(int asize, i if (aalloc != a) { ptr = static_cast(malloc(aalloc * sizeof(T))); Q_CHECK_PTR(ptr); - if (ptr) { - s = 0; - a = aalloc; - - if (QTypeInfo::isStatic) { - // copy all the old elements - while (s < copySize) { - new (ptr+s) T(*(oldPtr+s)); - (oldPtr+s)->~T(); - s++; - } - } else { - memcpy(ptr, oldPtr, copySize * sizeof(T)); + s = 0; + a = aalloc; + + if (QTypeInfo::isStatic) { + // copy all the old elements + while (s < copySize) { + new (ptr+s) T(*(oldPtr+s)); + (oldPtr+s)->~T(); + s++; } } else { - ptr = oldPtr; - return; + memcpy(ptr, oldPtr, copySize * sizeof(T)); } } s = copySize; -- 2.11.0