Avoid UB in QList::removeAt()

Always keep the out of bounds check for backwards compatibility,
but warn about it, so that we can remove it in Qt 6.

Amends commit ebf695bc77

Change-Id: I3f1e7e8f9f20feb0b0f06ff9083c26682f1c7d3b
Reviewed-by: Richard Öhlinger <richard.oehlinger@adbsafegate.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Lars Knoll 2020-02-28 10:53:15 +01:00
parent dd704d4498
commit c3fc9a24d8

View File

@ -583,10 +583,13 @@ inline void QList<T>::removeAt(int i)
{
#if !QT_DEPRECATED_SINCE(5, 15)
Q_ASSERT_X(i >= 0 && i < p.size(), "QList<T>::removeAt", "index out of range");
#elif !defined(QT_NO_DEBUG)
if (i < 0 || i >= p.size())
#endif
if (i < 0 || i >= p.size()) {
#if !defined(QT_NO_DEBUG)
qWarning("QList::removeAt(): Index out of range.");
#endif
return;
}
detach();
node_destruct(reinterpret_cast<Node *>(p.at(i))); p.remove(i);
}