QXmlStreamSimpleStack: Q_CHECK_PTR() the correct pointer
Coverity complains that the QXmlStreamPrivateTagStack default ctor
dereferences nullptr. I haven't understood, yet, why it thinks that,
but manual inspection revealed a Q_CHECK_PTR() in
QXmlStreamSimpleStack::reserve(), called from push(), fingered by
Coverity, that comes too late: If Q_CHECK_PTR() is configured to throw
std::bad_alloc, then we'd leak the previous buffer if realloc()
failed, because we had already overwritten the old value.
Fix by moving the Q_CHECK_PTR to after the realloc() and before the
assignment of the realloc() result to the data member.
Fingers cross that this fixes Coverity's complaint, too.
Amends 403343039d.
Coverity-Id: 474174
Pick-to: 6.5
Change-Id: Ib3564c34626950b927aa54df50abeecc42e8e674
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit fc00de90bb93fa0f7ba11da696c0ed408efa100b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 84675a6b5cbe047e294161b2b42930731dbda759)
(cherry picked from commit 1747f783d7d613e416019dcebf411517db9ffc8b)
This commit is contained in:
committed by
Qt Cherry-pick Bot
parent
5362c11f39
commit
a99b251571
@@ -140,8 +140,8 @@ public:
|
||||
if (tos + extraCapacity + 1 > cap) {
|
||||
cap = qMax(tos + extraCapacity + 1, cap << 1 );
|
||||
void *ptr = realloc(static_cast<void *>(data), cap * sizeof(T));
|
||||
Q_CHECK_PTR(ptr);
|
||||
data = reinterpret_cast<T *>(ptr);
|
||||
Q_CHECK_PTR(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user