diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-02-28 10:53:15 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-03-03 11:39:56 +0100 |
commit | c3fc9a24d8695447416b0eb40590fabea7287444 (patch) | |
tree | 1d6441985a405b71397fc1c7014c0e3e2de0d976 /src/corelib/tools | |
parent | dd704d44989e6481460e8d326b3faf4f1a781ad4 (diff) |
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 ebf695bc779a63a5730df05ab246305c0ab342e4
Change-Id: I3f1e7e8f9f20feb0b0f06ff9083c26682f1c7d3b
Reviewed-by: Richard Öhlinger <richard.oehlinger@adbsafegate.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qlist.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 37258cc66f..8a11663c01 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -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); } |