Instead of aggregating a QMutableSinglePointEvent by value, which depends on the QEvent copy assignment operator, and casting it to a QMouseEvent that it isn't, introduce QEventStorage which is a bit like std::optional, but, by each event subclass befriending it, can store event copies by-value, unlike clone(), which is restricted to the heap. We could have befriended std::optional<QMouseEvent>, too, but by adding our own type in _p.h, we can better control which code uses this dangerous construct. Added a guard to avoid clobbering lastMouseEvent with a copy of itself in storeMouseEvent(). Before, we'd self-assign to lastMouseEvent, which didn't invalidate the reference. Now, a store() is the equivalent of a dtor + copy constructor, so we need to be a bit more careful. Fixes UBSan reports when running tst_qgraphicsview: qgraphicsview/qgraphicsview.cpp:612:27: runtime error: downcast of address 0x61a000035e90 which does not point to an object of type 'QMouseEvent' 0x61a000035e90: note: object is of type 'QMutableSinglePointEvent' 00 00 00 00 30 47 ef 8b 99 7f 00 00 02 00 00 00 00 00 00 e0 d0 91 00 00 20 60 00 00 00 00 00 00 ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QMutableSinglePointEvent' #0 0x7f99a27c7a47 in QGraphicsViewPrivate::replayLastMouseEvent() qgraphicsview.cpp:612 qgraphicsview.cpp:653:39: runtime error: member call on address 0x61a0000fe290 which does not point to an object of type 'QMouseEvent' 0x61a0000fe290: note: object is of type 'QMutableSinglePointEvent' 00 00 00 00 30 47 ef 8b 99 7f 00 00 05 00 00 00 00 00 00 e0 d0 91 00 00 20 60 00 00 00 00 00 00 ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QMutableSinglePointEvent' #0 0x7f99a27c3609 in QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent*) qgraphicsview.cpp:653 #1 0x7f99a27c7832 in QGraphicsViewPrivate::replayLastMouseEvent() qgraphicsview.cpp:612 qgraphicsview.cpp:654:37: runtime error: member call on address 0x61a0000fe290 which does not point to an object of type 'QMouseEvent' 0x61a0000fe290: note: object is of type 'QMutableSinglePointEvent' 00 00 00 00 30 47 ef 8b 99 7f 00 00 05 00 00 00 00 00 00 e0 d0 91 00 00 20 60 00 00 00 00 00 00 ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QMutableSinglePointEvent' #0 0x7f99a27c358b in QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent*) qgraphicsview.cpp:654 #1 0x7f99a27c7832 in QGraphicsViewPrivate::replayLastMouseEvent() qgraphicsview.cpp:612 Task-number: QTBUG-99563 Change-Id: Ib642d416b8aef98c7fd8b1fa164ec2449189992a Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit dd264cc9c00e09eb995f1c6f9b1fd651f1d4b2f4) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
…
…
Description
Languages
C++
84.3%
HTML
4.9%
C
3.9%
CMake
3.6%
Objective-C++
2%
Other
0.8%