summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2025-03-22 17:56:55 +0100
committerMarc Mutz <[email protected]>2025-03-23 13:25:39 +0100
commitf4dd7e29a68c4439e3da40db4eb2d67999d316b0 (patch)
treec3ec6a4fbf75b6a99103dfbcc7b25cc0a126621e /src
parent22e212b6855f0e351b3b6a5a22b108e0bb53b986 (diff)
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.9 6.8 Change-Id: Ia3f6c08b62f6bed274f43baab881a0d802bd986b Reviewed-by: Thorbjørn Lund Martsum <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/dialogs/qmessagebox.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp
index b2a7ad274b2..df17399ca7e 100644
--- a/src/widgets/dialogs/qmessagebox.cpp
+++ b/src/widgets/dialogs/qmessagebox.cpp
@@ -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)