From 3ad55194a4a44e08a8e0c7a8bdad3f7594ef6d33 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 23 Feb 2021 14:48:12 +0100 Subject: [PATCH] Assert that we have a layout before dereferencing Since we test the pointer in the beginning, it might be nullptr. But if we receive events that require a layout, then it must not be nullptr. Assert that assumption. Address static analyzer warning 06f8cc945ead26f20c6b9599faf76c83. Change-Id: I1c6eb9e9d2c9444fcb9bd1d1d9c345237dc72b33 Reviewed-by: Richard Moe Gustavsen (cherry picked from commit 1f6dbbd53969837cc4ff59f39dbb4c06d700a689) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/widgets/qmainwindow.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp index 9c7b1d6aab4..4e7f04de6c9 100644 --- a/src/widgets/widgets/qmainwindow.cpp +++ b/src/widgets/widgets/qmainwindow.cpp @@ -1306,6 +1306,7 @@ bool QMainWindow::event(QEvent *event) #if QT_CONFIG(toolbar) case QEvent::ToolBarChange: { + Q_ASSERT(d->layout); d->layout->toggleToolBarsVisible(); return true; } @@ -1314,6 +1315,7 @@ bool QMainWindow::event(QEvent *event) #if QT_CONFIG(statustip) case QEvent::StatusTip: #if QT_CONFIG(statusbar) + Q_ASSERT(d->layout); if (QStatusBar *sb = d->layout->statusBar()) sb->showMessage(static_cast(event)->tip()); else @@ -1324,6 +1326,7 @@ bool QMainWindow::event(QEvent *event) case QEvent::StyleChange: #if QT_CONFIG(dockwidget) + Q_ASSERT(d->layout); d->layout->layoutState.dockAreaLayout.styleChangedEvent(); #endif if (!d->explicitIconSize)