summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <[email protected]>2024-11-12 12:34:15 +0100
committerAllan Sandfeld Jensen <[email protected]>2024-11-13 15:22:26 +0100
commitacc3ef6653c710b509e9321663986910f88ac3b4 (patch)
tree42d1b5997e7709bfa618982996e149c390974f27
parentbbeb1a8343117fd22fb1abf555d46298c0f370af (diff)
Fix ubsan warning of illegal cast and illegal method call
Avoid casting an event to a type it does not have. Instead use a static accessor class. Pick-to: 6.8 Task-number: QTBUG-99563 Change-Id: Ideb11779b1510cd10a27fb8bc40bcc8e4849bf15 Reviewed-by: Marc Mutz <[email protected]>
-rw-r--r--src/gui/kernel/qevent.cpp18
-rw-r--r--src/gui/kernel/qevent.h2
-rw-r--r--src/gui/kernel/qevent_p.h14
-rw-r--r--src/gui/kernel/qguiapplication.cpp2
-rw-r--r--src/gui/kernel/qpointingdevice.cpp2
-rw-r--r--src/widgets/graphicsview/qgraphicsview.cpp2
-rw-r--r--src/widgets/kernel/qapplication.cpp8
-rw-r--r--src/widgets/kernel/qwidgetwindow.cpp4
8 files changed, 37 insertions, 15 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 91374355d03..fa28aff7dc1 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -4804,19 +4804,27 @@ QMutableTouchEvent::~QMutableTouchEvent()
/*! \internal
Add the given \a point.
*/
-void QMutableTouchEvent::addPoint(const QEventPoint &point)
+void QMutableTouchEvent::addPoint(QTouchEvent *e, const QEventPoint &point)
{
- m_points.append(point);
- auto &added = m_points.last();
+ e->m_points.append(point);
+ auto &added = e->m_points.last();
if (!added.device())
- QMutableEventPoint::setDevice(added, pointingDevice());
- m_touchPointStates |= point.state();
+ QMutableEventPoint::setDevice(added, e->pointingDevice());
+ e->m_touchPointStates |= point.state();
}
QMutableSinglePointEvent::~QMutableSinglePointEvent()
= default;
+/*! \internal
+ Add the given \a point.
+*/
+void QMutableTouchEvent::addPoint(const QEventPoint &point)
+{
+ addPoint(this, point);
+}
+
QT_END_NAMESPACE
#include "moc_qevent.cpp"
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index d257e50b5c5..82c309b8d0a 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -134,6 +134,7 @@ public:
protected:
friend class ::tst_QEvent;
+ friend class QMutableSinglePointEvent;
QSinglePointEvent(Type type, const QPointingDevice *dev, const QEventPoint &point,
Qt::MouseButton button, Qt::MouseButtons buttons,
Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source);
@@ -944,6 +945,7 @@ public:
bool isEndEvent() const override;
protected:
+ friend class QMutableTouchEvent;
QObject *m_target = nullptr;
QEventPoint::States m_touchPointStates = QEventPoint::State::Unknown;
quint32 m_reserved : 24;
diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h
index 96ef8f123e9..67be26b8c8c 100644
--- a/src/gui/kernel/qevent_p.h
+++ b/src/gui/kernel/qevent_p.h
@@ -39,8 +39,10 @@ public:
static QMutableTouchEvent &from(QTouchEvent &e) { return static_cast<QMutableTouchEvent &>(e); }
void setTarget(QObject *target) { m_target = target; }
-
void addPoint(const QEventPoint &point);
+
+ static void setTarget(QTouchEvent *e, QObject *target) { e->m_target = target; }
+ static void addPoint(QTouchEvent *e, const QEventPoint &point);
};
class Q_GUI_EXPORT QMutableSinglePointEvent : public QSinglePointEvent
@@ -63,6 +65,16 @@ public:
bool isDoubleClick() { return m_doubleClick; }
void setDoubleClick(bool d = true) { m_doubleClick = d; }
+
+ static bool isDoubleClick(const QSinglePointEvent *ev)
+ {
+ return ev->m_doubleClick;
+ }
+
+ static void setDoubleClick(QSinglePointEvent *ev, bool d)
+ {
+ ev->m_doubleClick = d;
+ }
};
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 0f531cb280d..f72b768e4f9 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -2459,7 +2459,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
// QtBUG-25831, used to suppress delivery in qwidgetwindow.cpp
- QMutableSinglePointEvent::from(ev).setDoubleClick();
+ QMutableSinglePointEvent::setDoubleClick(&ev, true);
}
QGuiApplication::sendSpontaneousEvent(window, &ev);
diff --git a/src/gui/kernel/qpointingdevice.cpp b/src/gui/kernel/qpointingdevice.cpp
index c4c1e5fd5c1..ef534b19cd0 100644
--- a/src/gui/kernel/qpointingdevice.cpp
+++ b/src/gui/kernel/qpointingdevice.cpp
@@ -407,7 +407,7 @@ void QPointingDevicePrivate::sendTouchCancelEvent(QTouchEvent *cancelEvent)
if (cancelEvent->points().isEmpty()) {
for (auto &epd : activePoints.values()) {
if (epd.exclusiveGrabber)
- QMutableTouchEvent::from(cancelEvent)->addPoint(epd.eventPoint);
+ QMutableTouchEvent::addPoint(cancelEvent, epd.eventPoint);
}
}
for (auto &epd : activePoints.values()) {
diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp
index deb647a9729..ecc633c269d 100644
--- a/src/widgets/graphicsview/qgraphicsview.cpp
+++ b/src/widgets/graphicsview/qgraphicsview.cpp
@@ -2902,7 +2902,7 @@ bool QGraphicsView::viewportEvent(QEvent *event)
if (d->scene && d->sceneInteractionAllowed) {
// Convert and deliver the touch event to the scene.
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
- QMutableTouchEvent::from(touchEvent)->setTarget(viewport());
+ QMutableTouchEvent::setTarget(touchEvent, viewport());
QGraphicsViewPrivate::translateTouchEvent(d, touchEvent);
QCoreApplication::sendEvent(d->scene, touchEvent);
} else {
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index e8c7598a826..bc6710d1981 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -2762,7 +2762,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
mouse->pointingDevice());
me.m_spont = mouse->spontaneous();
me.setTimestamp(mouse->timestamp());
- QMutableSinglePointEvent::from(me).setDoubleClick(QMutableSinglePointEvent::from(mouse)->isDoubleClick());
+ QMutableSinglePointEvent::setDoubleClick(&me, QMutableSinglePointEvent::isDoubleClick(mouse));
// throw away any mouse-tracking-only mouse events
if (!w->hasMouseTracking()
&& mouse->type() == QEvent::MouseMove && mouse->buttons() == 0) {
@@ -3067,7 +3067,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
#endif // QT_CONFIG(draganddrop)
case QEvent::TouchBegin: {
// Note: TouchUpdate and TouchEnd events are never propagated
- QMutableTouchEvent *touchEvent = QMutableTouchEvent::from(static_cast<QTouchEvent *>(e));
+ QTouchEvent *touchEvent = static_cast<QTouchEvent *>(e);
bool eventAccepted = touchEvent->isAccepted();
bool acceptTouchEvents = w->testAttribute(Qt::WA_AcceptTouchEvents);
@@ -3084,7 +3084,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
while (w) {
// first, try to deliver the touch event
acceptTouchEvents = w->testAttribute(Qt::WA_AcceptTouchEvents);
- touchEvent->setTarget(w);
+ QMutableTouchEvent::setTarget(touchEvent, w);
touchEvent->setAccepted(acceptTouchEvents);
QPointer<QWidget> p = w;
res = acceptTouchEvents && d->notify_helper(w, touchEvent);
@@ -3110,7 +3110,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
const QPoint offset = w->pos();
w = w->parentWidget();
- touchEvent->setTarget(w);
+ QMutableTouchEvent::setTarget(touchEvent, w);
for (int i = 0; i < touchEvent->pointCount(); ++i) {
auto &pt = touchEvent->point(i);
QMutableEventPoint::setPosition(pt, pt.position() + offset);
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index 1d2b7dfadbf..1295cf68ea6 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -564,7 +564,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
}
}
- if ((event->type() != QEvent::MouseButtonPress) || !(QMutableSinglePointEvent::from(event)->isDoubleClick())) {
+ if ((event->type() != QEvent::MouseButtonPress) || !(QMutableSinglePointEvent::isDoubleClick(event))) {
// if the widget that was pressed is gone, then deliver move events without buttons
const auto buttons = event->type() == QEvent::MouseMove && qt_popup_down_closed
? Qt::NoButton : event->buttons();
@@ -656,7 +656,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
mapped = event->position().toPoint();
}
- if ((event->type() != QEvent::MouseButtonPress) || !QMutableSinglePointEvent::from(event)->isDoubleClick()) {
+ if ((event->type() != QEvent::MouseButtonPress) || !QMutableSinglePointEvent::isDoubleClick(event)) {
// The preceding statement excludes MouseButtonPress events which caused
// creation of a MouseButtonDblClick event. QTBUG-25831