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. Task-number: QTBUG-99563 Change-Id: Ideb11779b1510cd10a27fb8bc40bcc8e4849bf15 Reviewed-by: Marc Mutz <marc.mutz@qt.io> (cherry picked from commit acc3ef6653c710b509e9321663986910f88ac3b4) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
3b541daff7
commit
b52a0f8e10
@ -4804,19 +4804,27 @@ QMutableTouchEvent::~QMutableTouchEvent()
|
|||||||
/*! \internal
|
/*! \internal
|
||||||
Add the given \a point.
|
Add the given \a point.
|
||||||
*/
|
*/
|
||||||
void QMutableTouchEvent::addPoint(const QEventPoint &point)
|
void QMutableTouchEvent::addPoint(QTouchEvent *e, const QEventPoint &point)
|
||||||
{
|
{
|
||||||
m_points.append(point);
|
e->m_points.append(point);
|
||||||
auto &added = m_points.last();
|
auto &added = e->m_points.last();
|
||||||
if (!added.device())
|
if (!added.device())
|
||||||
QMutableEventPoint::setDevice(added, pointingDevice());
|
QMutableEventPoint::setDevice(added, e->pointingDevice());
|
||||||
m_touchPointStates |= point.state();
|
e->m_touchPointStates |= point.state();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QMutableSinglePointEvent::~QMutableSinglePointEvent()
|
QMutableSinglePointEvent::~QMutableSinglePointEvent()
|
||||||
= default;
|
= default;
|
||||||
|
|
||||||
|
/*! \internal
|
||||||
|
Add the given \a point.
|
||||||
|
*/
|
||||||
|
void QMutableTouchEvent::addPoint(const QEventPoint &point)
|
||||||
|
{
|
||||||
|
addPoint(this, point);
|
||||||
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
#include "moc_qevent.cpp"
|
#include "moc_qevent.cpp"
|
||||||
|
@ -134,6 +134,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class ::tst_QEvent;
|
friend class ::tst_QEvent;
|
||||||
|
friend class QMutableSinglePointEvent;
|
||||||
QSinglePointEvent(Type type, const QPointingDevice *dev, const QEventPoint &point,
|
QSinglePointEvent(Type type, const QPointingDevice *dev, const QEventPoint &point,
|
||||||
Qt::MouseButton button, Qt::MouseButtons buttons,
|
Qt::MouseButton button, Qt::MouseButtons buttons,
|
||||||
Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source);
|
Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source);
|
||||||
@ -943,6 +944,7 @@ public:
|
|||||||
bool isEndEvent() const override;
|
bool isEndEvent() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
friend class QMutableTouchEvent;
|
||||||
QObject *m_target = nullptr;
|
QObject *m_target = nullptr;
|
||||||
QEventPoint::States m_touchPointStates = QEventPoint::State::Unknown;
|
QEventPoint::States m_touchPointStates = QEventPoint::State::Unknown;
|
||||||
quint32 m_reserved : 24;
|
quint32 m_reserved : 24;
|
||||||
|
@ -39,8 +39,10 @@ public:
|
|||||||
static QMutableTouchEvent &from(QTouchEvent &e) { return static_cast<QMutableTouchEvent &>(e); }
|
static QMutableTouchEvent &from(QTouchEvent &e) { return static_cast<QMutableTouchEvent &>(e); }
|
||||||
|
|
||||||
void setTarget(QObject *target) { m_target = target; }
|
void setTarget(QObject *target) { m_target = target; }
|
||||||
|
|
||||||
void addPoint(const QEventPoint &point);
|
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
|
class Q_GUI_EXPORT QMutableSinglePointEvent : public QSinglePointEvent
|
||||||
@ -63,6 +65,16 @@ public:
|
|||||||
bool isDoubleClick() { return m_doubleClick; }
|
bool isDoubleClick() { return m_doubleClick; }
|
||||||
|
|
||||||
void setDoubleClick(bool d = true) { m_doubleClick = d; }
|
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
|
QT_END_NAMESPACE
|
||||||
|
@ -2455,7 +2455,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
|
|||||||
|
|
||||||
if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
|
if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
|
||||||
// QtBUG-25831, used to suppress delivery in qwidgetwindow.cpp
|
// QtBUG-25831, used to suppress delivery in qwidgetwindow.cpp
|
||||||
QMutableSinglePointEvent::from(ev).setDoubleClick();
|
QMutableSinglePointEvent::setDoubleClick(&ev, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
QGuiApplication::sendSpontaneousEvent(window, &ev);
|
QGuiApplication::sendSpontaneousEvent(window, &ev);
|
||||||
|
@ -407,7 +407,7 @@ void QPointingDevicePrivate::sendTouchCancelEvent(QTouchEvent *cancelEvent)
|
|||||||
if (cancelEvent->points().isEmpty()) {
|
if (cancelEvent->points().isEmpty()) {
|
||||||
for (auto &epd : activePoints.values()) {
|
for (auto &epd : activePoints.values()) {
|
||||||
if (epd.exclusiveGrabber)
|
if (epd.exclusiveGrabber)
|
||||||
QMutableTouchEvent::from(cancelEvent)->addPoint(epd.eventPoint);
|
QMutableTouchEvent::addPoint(cancelEvent, epd.eventPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto &epd : activePoints.values()) {
|
for (auto &epd : activePoints.values()) {
|
||||||
|
@ -2902,7 +2902,7 @@ bool QGraphicsView::viewportEvent(QEvent *event)
|
|||||||
if (d->scene && d->sceneInteractionAllowed) {
|
if (d->scene && d->sceneInteractionAllowed) {
|
||||||
// Convert and deliver the touch event to the scene.
|
// Convert and deliver the touch event to the scene.
|
||||||
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
|
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
|
||||||
QMutableTouchEvent::from(touchEvent)->setTarget(viewport());
|
QMutableTouchEvent::setTarget(touchEvent, viewport());
|
||||||
QGraphicsViewPrivate::translateTouchEvent(d, touchEvent);
|
QGraphicsViewPrivate::translateTouchEvent(d, touchEvent);
|
||||||
QCoreApplication::sendEvent(d->scene, touchEvent);
|
QCoreApplication::sendEvent(d->scene, touchEvent);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2762,7 +2762,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
|
|||||||
mouse->pointingDevice());
|
mouse->pointingDevice());
|
||||||
me.m_spont = mouse->spontaneous();
|
me.m_spont = mouse->spontaneous();
|
||||||
me.setTimestamp(mouse->timestamp());
|
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
|
// throw away any mouse-tracking-only mouse events
|
||||||
if (!w->hasMouseTracking()
|
if (!w->hasMouseTracking()
|
||||||
&& mouse->type() == QEvent::MouseMove && mouse->buttons() == 0) {
|
&& mouse->type() == QEvent::MouseMove && mouse->buttons() == 0) {
|
||||||
@ -3067,7 +3067,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
|
|||||||
#endif // QT_CONFIG(draganddrop)
|
#endif // QT_CONFIG(draganddrop)
|
||||||
case QEvent::TouchBegin: {
|
case QEvent::TouchBegin: {
|
||||||
// Note: TouchUpdate and TouchEnd events are never propagated
|
// 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 eventAccepted = touchEvent->isAccepted();
|
||||||
bool acceptTouchEvents = w->testAttribute(Qt::WA_AcceptTouchEvents);
|
bool acceptTouchEvents = w->testAttribute(Qt::WA_AcceptTouchEvents);
|
||||||
|
|
||||||
@ -3084,7 +3084,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
|
|||||||
while (w) {
|
while (w) {
|
||||||
// first, try to deliver the touch event
|
// first, try to deliver the touch event
|
||||||
acceptTouchEvents = w->testAttribute(Qt::WA_AcceptTouchEvents);
|
acceptTouchEvents = w->testAttribute(Qt::WA_AcceptTouchEvents);
|
||||||
touchEvent->setTarget(w);
|
QMutableTouchEvent::setTarget(touchEvent, w);
|
||||||
touchEvent->setAccepted(acceptTouchEvents);
|
touchEvent->setAccepted(acceptTouchEvents);
|
||||||
QPointer<QWidget> p = w;
|
QPointer<QWidget> p = w;
|
||||||
res = acceptTouchEvents && d->notify_helper(w, touchEvent);
|
res = acceptTouchEvents && d->notify_helper(w, touchEvent);
|
||||||
@ -3110,7 +3110,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
|
|||||||
|
|
||||||
const QPoint offset = w->pos();
|
const QPoint offset = w->pos();
|
||||||
w = w->parentWidget();
|
w = w->parentWidget();
|
||||||
touchEvent->setTarget(w);
|
QMutableTouchEvent::setTarget(touchEvent, w);
|
||||||
for (int i = 0; i < touchEvent->pointCount(); ++i) {
|
for (int i = 0; i < touchEvent->pointCount(); ++i) {
|
||||||
auto &pt = touchEvent->point(i);
|
auto &pt = touchEvent->point(i);
|
||||||
QMutableEventPoint::setPosition(pt, pt.position() + offset);
|
QMutableEventPoint::setPosition(pt, pt.position() + offset);
|
||||||
|
@ -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
|
// 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
|
const auto buttons = event->type() == QEvent::MouseMove && qt_popup_down_closed
|
||||||
? Qt::NoButton : event->buttons();
|
? Qt::NoButton : event->buttons();
|
||||||
@ -656,7 +656,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
|
|||||||
mapped = event->position().toPoint();
|
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
|
// The preceding statement excludes MouseButtonPress events which caused
|
||||||
// creation of a MouseButtonDblClick event. QTBUG-25831
|
// creation of a MouseButtonDblClick event. QTBUG-25831
|
||||||
|
Loading…
x
Reference in New Issue
Block a user