summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-01-04 19:43:49 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-01-14 19:48:54 +0000
commit200a210323f477d60e280d15e09ca39bedd81a7c (patch)
treeff70203a060d2c347a822f1a2cfa0ee677f713ed /src/gui/kernel
parentc827990b7cc2fe5d2aa499b5fb936fd728c5f18f (diff)
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 3d71c4b740d23d5c3f380f495990f35ea17dc2a0. Change-Id: I8455c998e2f4390a1483c1a097eb095358963ace Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit efe4863f837834c1664e37bf439bdec399f1dc88) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qwindow.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index 030628b5db..a167d6e249 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -2556,7 +2556,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(),