Marc Mutz cbc2f2a6ee QFileDialog: fix UB (invalid cast) in Private::setVisible()
The function can be called from ~QDialog(), in which case a cast of
q_ptr to QFileDialog is UB.

Says UBSan:

  qfiledialog_p.h:78:5: runtime error: downcast of address 0x7ffe7a8ad5a0 which does not point to an object of type 'QFileDialog'
  0x7ffe7a8ad5a0: note: object is of type 'QDialog'
   fe 7f 00 00  30 44 d8 fb d2 7f 00 00  80 b4 00 00 90 61 00 00  08 46 d8 fb d2 7f 00 00  00 00 00 00
                ^~~~~~~~~~~~~~~~~~~~~~~
                vptr for 'QDialog'
    #0 0x7fd2f96d7587 in QFileDialogPrivate::q_func() qfiledialog_p.h:78
    #1 0x7fd2f96d7587 in QFileDialogPrivate::setVisible(bool) qfiledialog.cpp:860
    #2 0x7fd2f95465f5 in QDialog::setVisible(bool) qdialog.cpp:757
    #3 0x7fd2f6d88768 in QWidget::hide() qwidget.cpp:8179
    #4 0x7fd2f9545e09 in QDialog::~QDialog() qdialog.cpp:398

Fix by casting to QFileDialog only on show() (in createWidgets()), not
hide(), and otherwise cast at most to QDialog* (QWidget* would
actually have sufficed).

Add a code comment.

Amends e0bb9e81ab1a9d71f2893844ea82430467422e21 (I think; it might
have been present in a different form before that).

Pick-to: 6.8 6.5
Change-Id: I4e206f7c36c03e8cb8a36001beae283628960073
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit a6743bd3c787e03d2ee3b791260e21e539131181)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-26 12:35:23 +00:00
2025-03-24 18:27:25 +00:00
2024-11-05 14:36:16 +01:00
2015-08-18 19:59:14 +00:00
2024-11-05 14:36:16 +01:00
2025-03-25 08:40:27 +00:00
2024-06-25 11:44:00 +02:00
Description
Qt Base (Core, Gui, Widgets, Network, ...)
822 MiB
Languages
C++ 84.3%
HTML 4.9%
C 3.9%
CMake 3.6%
Objective-C++ 2%
Other 0.8%