Commit 5571d2bf authored by Marc Mutz's avatar Marc Mutz
Browse files

tst_QApplication: Fix UBs (invalid cast) in focusMouseClick()

Found by UBSan:

  tst_qapplication.cpp:1754:48: runtime error: member access within address 0x7ffda11f2220 which does not point to an object of type 'SpontaneousEvent'
  0x7ffda11f2220: note: object is of type 'QMouseEvent'

The code attempted to model the layout of a QEvent with another class
that allows public access to the memory location that (hopefully)
corresponds to QEvent::spont, gaining access by casting a QEvent
object to that specifically-crafted class.

Fix by the using the existing QSpontaneKeyEvent::setSpontaneous()
call, which, despite its name, works for all QEvent subclasses, and
which has already been fixed to not invoke UB (in bc087db5

).

Change-Id: I7db8b8a8a823f7d61ab17375142d19dc3874fea5
Reviewed-by: default avatarOlivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Showing with 3 additions and 22 deletions
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment