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>
bb10
Marcel Kummer 2022-06-15 13:23:00 +02:00
parent f23d83c43e
commit e457aeec38
1 changed files with 1 additions and 0 deletions

View File

@ -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;
}