From 68a8a8b30952f30ab76018a14e40680944c2501c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 2 Feb 2024 11:22:50 +0100 Subject: [PATCH] Harden WidgetAttributes debug stream operator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The call site may pass in a null-widget, so guard for that. Change-Id: I631cb2fc105bad69faf3daaeac4b893457d27cc1 Reviewed-by: Edward Welbourne (cherry picked from commit 97c02b80ae28d9bdc4e01980296e0db67f194f81) Reviewed-by: Tor Arne Vestbø --- src/widgets/kernel/qwidget.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 2a4a9c0a5bb..baababe09ae 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -13214,16 +13214,17 @@ QDebug operator<<(QDebug debug, const WidgetAttributes &attributes) { const QDebugStateSaver saver(debug); debug.nospace(); - const QWidget *widget = attributes.widget; - const QMetaObject *qtMo = qt_getEnumMetaObject(Qt::WA_AttributeCount); - const QMetaEnum me = qtMo->enumerator(qtMo->indexOfEnumerator("WidgetAttribute")); debug << '['; - int count = 0; - for (int a = 0; a < Qt::WA_AttributeCount; ++a) { - if (widget->testAttribute(static_cast(a))) { - if (count++) - debug << ','; - debug << me.valueToKey(a); + if (const QWidget *widget = attributes.widget) { + const QMetaObject *qtMo = qt_getEnumMetaObject(Qt::WA_AttributeCount); + const QMetaEnum me = qtMo->enumerator(qtMo->indexOfEnumerator("WidgetAttribute")); + int count = 0; + for (int a = 0; a < Qt::WA_AttributeCount; ++a) { + if (widget->testAttribute(static_cast(a))) { + if (count++) + debug << ','; + debug << me.valueToKey(a); + } } } debug << ']';