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 <Friedemann.Kleint@qt.io>
(cherry picked from commit 3b3b5968d0a51a1aa3a402f8e042f3a5a2c3329e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-03-26 10:27:44 +01:00 committed by Qt Cherry-pick Bot
parent 2c9baee470
commit 9747e0a8b1

View File

@ -4434,7 +4434,7 @@ bool QAbstractItemViewPrivate::shouldAutoScroll(const QPoint &pos) const
{
if (!autoScroll)
return false;
QRect area = static_cast<QAbstractItemView*>(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)