From e457aeec3802e79d33347768cb9c50eb87deed92 Mon Sep 17 00:00:00 2001 From: Marcel Kummer Date: Wed, 15 Jun 2022 13:23:00 +0200 Subject: [PATCH] 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 --- src/widgets/kernel/qboxlayout.cpp | 1 + 1 file changed, 1 insertion(+) 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; }