From 9747e0a8b19a8fe81a9764e0d13e57f12d80c4aa Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 26 Mar 2025 10:27:44 +0100 Subject: [PATCH] QAbstractItemView: fix UB (invalid downcast) in Private::shouldAutoScroll() Says UBSan: qabstractitemview.cpp:4442:18: runtime error: downcast of address 0x604000026790 which does not point to an object of type 'QAbstractItemView' 0x604000026790: note: object is of type 'QWidget' 00 00 00 00 08 b1 cf 9f 33 7f 00 00 80 24 00 00 60 61 00 00 b8 b2 cf 9f 33 7f 00 00 00 00 be be ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QWidget' I did not reserch what the problem was that the code comment referred to, but we now have QWidgetPrivate::get() (incl. in 5.15), so use that. Amends the start of the public history. Pick-to: 6.8 6.5 5.15 Change-Id: If658d21694f6806eafdf678b8d5ff7ed62e93513 Reviewed-by: Friedemann Kleint (cherry picked from commit 3b3b5968d0a51a1aa3a402f8e042f3a5a2c3329e) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/itemviews/qabstractitemview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index d5744b456ab..090ac232a6e 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -4434,7 +4434,7 @@ bool QAbstractItemViewPrivate::shouldAutoScroll(const QPoint &pos) const { if (!autoScroll) return false; - QRect area = static_cast(viewport)->d_func()->clipRect(); // access QWidget private by bending C++ rules + const QRect area = QWidgetPrivate::get(viewport)->clipRect(); return (pos.y() - area.top() < autoScrollMargin) || (area.bottom() - pos.y() < autoScrollMargin) || (pos.x() - area.left() < autoScrollMargin)