QWindow: fix UB (invalid static_cast)
Do the cast to QMouseEvent only after we determined that it's actually
a QMouseEvent. Says ubsan:
src/gui/kernel/qwindow.cpp:2558:27: runtime error: downcast of address 0x7fffca0e5af0 which does not point to an object of type 'QMouseEvent'
0x7fffca0e5af0: note: object is of type 'QShowEvent'
ff 7f 00 00 b0 09 01 b8 61 7f 00 00 11 00 00 00 00 00 00 00 b3 8a b5 41 00 00 00 00 80 50 5a cc
^~~~~~~~~~~~~~~~~~~~~~~
vptr for 'QShowEvent'
Only cast _after_ determining that `ev` is-a mouse event.
Amends 3d71c4b740
.
Pick-to: 6.3 6.2
Change-Id: I8455c998e2f4390a1483c1a097eb095358963ace
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
7955dceec1
commit
efe4863f83
@ -2559,7 +2559,12 @@ bool QWindow::event(QEvent *ev)
|
||||
static const QEvent::Type contextMenuTrigger =
|
||||
QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() ?
|
||||
QEvent::MouseButtonRelease : QEvent::MouseButtonPress;
|
||||
if (QMouseEvent *me = static_cast<QMouseEvent *>(ev);
|
||||
auto asMouseEvent = [](QEvent *ev) {
|
||||
const auto t = ev->type();
|
||||
return t == QEvent::MouseButtonPress || t == QEvent::MouseButtonRelease
|
||||
? static_cast<QMouseEvent *>(ev) : nullptr ;
|
||||
};
|
||||
if (QMouseEvent *me = asMouseEvent(ev); me &&
|
||||
ev->type() == contextMenuTrigger && me->button() == Qt::RightButton) {
|
||||
QSinglePointEvent *pev = static_cast<QSinglePointEvent*>(ev);
|
||||
QContextMenuEvent e(QContextMenuEvent::Mouse, me->position().toPoint(),
|
||||
|
Loading…
Reference in New Issue
Block a user