diff options
author | Marcel Kummer <marcel.kummer@qt.io> | 2022-06-15 13:23:00 +0200 |
---|---|---|
committer | Marcel Kummer <marcel.kummer@qt.io> | 2022-06-18 21:07:51 +0200 |
commit | e457aeec3802e79d33347768cb9c50eb87deed92 (patch) | |
tree | b627a1e27aff295044e1e85f2bfde5ef7bed2296 /src/widgets/kernel | |
parent | f23d83c43e1c4a462014f0d27596a06f7bc8bf13 (diff) |
QBoxLayout: Add assertion that catches out of bounds insertion indices
As of Qt6, QList will assert that an insertion index is in range of
existing values. QBoxLayout interprets negative indices as "append at
the end". That part is covered.
Indices larger than the number of items in the layout would trigger the
assertion in QList, but after the insert method had returned. That would
make it hard to debug. This change asserts the index range before
inserting, thus making it easier to spot the problem.
Fixes: QTBUG-103775
Change-Id: Ida099f785263fe8a5c8a1d0a48c4ff87713549b4
Pick-to: 6.2 6.3 6.4
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r-- | src/widgets/kernel/qboxlayout.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/widgets/kernel/qboxlayout.cpp b/src/widgets/kernel/qboxlayout.cpp index 6384fda896..d16d903f53 100644 --- a/src/widgets/kernel/qboxlayout.cpp +++ b/src/widgets/kernel/qboxlayout.cpp @@ -413,6 +413,7 @@ int QBoxLayoutPrivate::validateIndex(int index) const if (index < 0) return list.count(); // append + Q_ASSERT_X(index >= 0 && index <= list.count(), "QBoxLayout::insert", "index out of range"); return index; } |