diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2020-11-10 19:43:52 +0100 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2020-11-12 09:53:49 +0100 |
commit | 405305069fc5f1a98719dbcff6a8a3cbd1714ab0 (patch) | |
tree | 386b0ec55a19c679279171fc44145c2edd802db8 /src/corelib/text/qbytearray.cpp | |
parent | 7549d1805422dad1ef1b08f25581b84fe1ce3335 (diff) |
Clean realloc() related bits in QString/QBA and Q*ArrayOps
Fixed misleading naming of "slowReallocatePath". It's no longer "slow",
it's downright dangerous now to reallocate under certain conditions
Added several asserts which should've been there already as our code
would run into a UB/crash anyhow - let's at least get extra checks
that are closer to the trouble causing places
Bring back the (slightly modified) code-cleaning changes from
504972f838761f79a170c22225add496e7e5af6a
Change-Id: Ie1358aebc619062d3991a78049e366dc0e8c267e
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/text/qbytearray.cpp')
-rw-r--r-- | src/corelib/text/qbytearray.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 14789c8a2c..bc2f73a67d 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -1708,12 +1708,11 @@ void QByteArray::reallocData(qsizetype alloc, QArrayData::AllocationOption optio return; } - // there's a case of slow reallocate path where we need to memmove the data - // before a call to ::realloc(), meaning that there's an extra "heavy" - // operation. just prefer ::malloc() branch in this case - const bool slowReallocatePath = d.freeSpaceAtBegin() > 0; + // don't use reallocate path when reducing capacity and there's free space + // at the beginning: might shift data pointer outside of allocated space + const bool cannotUseReallocate = d.freeSpaceAtBegin() > 0; - if (d->needsDetach() || slowReallocatePath) { + if (d->needsDetach() || cannotUseReallocate) { DataPointer dd(Data::allocate(alloc, option), qMin(alloc, d.size)); if (dd.size > 0) ::memcpy(dd.data(), d.data(), dd.size); |