From bc087db590ddaa68c6d3845bf4e6bd97abf83104 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 5 Mar 2016 11:31:27 +0100 Subject: QtTest: fix UB in QSpontaneKeyEvent::setSpontaneous() Found by UBSan: src/testlib/qtestspontaneevent.h:95:38: runtime error: member call on address 0x7ffc33019650 which does not point to an object of type 'QSpontaneKeyEvent' 0x7ffc33019650: note: object is of type 'QMouseEvent' 83 2b 00 00 98 e8 fa 8e 83 2b 00 00 00 00 00 00 00 00 00 00 02 00 04 00 00 00 00 00 00 00 00 00 ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QMouseEvent' src/testlib/qtestspontaneevent.h:95:38: runtime error: member call on address 0x7ffc330196e0 which does not point to an object of type 'QSpontaneKeyEvent' 0x7ffc330196e0: note: object is of type 'QKeyEvent' 00 00 00 00 f8 e8 fa 8e 83 2b 00 00 00 00 00 00 00 00 00 00 07 00 04 00 00 00 00 00 00 00 00 00 ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QKeyEvent' Fix by providing setSpontaneous() on QEvent as a private function and befriending QSpontaneKeyEvent. Make setSpontaneous() always-inline to avoid BiC between 5.6.0 and 5.6.1. Change-Id: Ic60d82ed6a858f4f13f41fa3d2d1db6e808896b7 Reviewed-by: Lars Knoll --- src/testlib/qtestspontaneevent.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'src/testlib') diff --git a/src/testlib/qtestspontaneevent.h b/src/testlib/qtestspontaneevent.h index 18c4221f72..bc775aa803 100644 --- a/src/testlib/qtestspontaneevent.h +++ b/src/testlib/qtestspontaneevent.h @@ -76,17 +76,10 @@ public: } #endif + // ### Qt 6: remove everything except this function: static inline void setSpontaneous(QEvent *ev) { - // use a union instead of a reinterpret_cast to prevent alignment warnings - union - { - QSpontaneKeyEvent *skePtr; - QEvent *evPtr; - } helper; - - helper.evPtr = ev; - helper.skePtr->setSpontaneous(); + ev->setSpontaneous(); } protected: -- cgit v1.2.3