From 0d997213a6a42d482e09c287421c34c35615ba9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Arve=20S=C3=A6ther?= Date: Wed, 8 Jan 2025 16:23:21 +0100 Subject: [PATCH] Fix bug QGridLayoutEngine::cellRect() lastColumn and lastRow could exceed the total column/row count, leading to out-of-bounds accesses to the QList QGridLayoutEngine::cellRect() is unused, so there is no risk of regressions here. We fix it because the function might be used later. So far the plan is to use it for visualizing the layout cells in QtQuick Layouts. Change-Id: Idd9db682039f2f81b3a6fbcd03990b6f15334d3e Reviewed-by: Mitch Curtis --- src/gui/util/qgridlayoutengine.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/util/qgridlayoutengine.cpp b/src/gui/util/qgridlayoutengine.cpp index 3e1eb869393..e8a6b56ae20 100644 --- a/src/gui/util/qgridlayoutengine.cpp +++ b/src/gui/util/qgridlayoutengine.cpp @@ -1070,8 +1070,8 @@ QRectF QGridLayoutEngine::cellRect(const QRectF &contentsGeometry, int row, int ensureGeometries(contentsGeometry.size(), styleInfo); - int lastColumn = qMax(column + columnSpan, columnCount()) - 1; - int lastRow = qMax(row + rowSpan, rowCount()) - 1; + int lastColumn = qMin(column + columnSpan, columnCount()) - 1; + int lastRow = qMin(row + rowSpan, rowCount()) - 1; qreal x = q_xx[column]; qreal y = q_yy[row];