QMessageBox: really fix UB (invalid cast) in Private::canBeNativeDialog()
The code comment above the cast is correct, but the code wasn't: While we're receiving the result of the cast in a QDialog pointer, the cast is still to QMessageBox*, and whether that cast is in the Q_Q macro or not doesn't change the fact that it's invalid. Says UBSan: qmessagebox.cpp:2804:31: runtime error: downcast of address 0x7ffebfd87140 which does not point to an object of type 'QMessageBox' 0x7ffebfd87140: note: object is of type 'QDialog' 2b 7f 00 00 30 94 57 b9 2b 7f 00 00 80 8c 00 00 90 61 00 00 08 96 57 b9 2b 7f 00 00 00 00 d8 bf ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QDialog' The trivial fix is to cast only to QDialog. Amends 29b2506e8cf0c792821a3ddb28e62080cd66ae28. Pick-to: 6.8 Change-Id: Ia3f6c08b62f6bed274f43baab881a0d802bd986b Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com> (cherry picked from commit f4dd7e29a68c4439e3da40db4eb2d67999d316b0) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
b10616fe3e
commit
607115f1e2
@ -2800,7 +2800,7 @@ bool QMessageBoxPrivate::canBeNativeDialog() const
|
||||
{
|
||||
// Don't use Q_Q here! This function is called from ~QDialog,
|
||||
// so Q_Q calling q_func() invokes undefined behavior (invalid cast in q_func()).
|
||||
const QDialog * const q = static_cast<const QMessageBox*>(q_ptr);
|
||||
const QDialog * const q = static_cast<const QDialog*>(q_ptr);
|
||||
if (nativeDialogInUse)
|
||||
return true;
|
||||
if (QCoreApplication::testAttribute(Qt::AA_DontUseNativeDialogs)
|
||||
|
Loading…
x
Reference in New Issue
Block a user