Harden WidgetAttributes debug stream operator

The call site may pass in a null-widget, so guard for that.

Change-Id: I631cb2fc105bad69faf3daaeac4b893457d27cc1
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit 97c02b80ae28d9bdc4e01980296e0db67f194f81)
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Tor Arne Vestbø 2024-02-02 11:22:50 +01:00
parent 5511f64ded
commit 68a8a8b309

View File

@ -13214,10 +13214,10 @@ QDebug operator<<(QDebug debug, const WidgetAttributes &attributes)
{ {
const QDebugStateSaver saver(debug); const QDebugStateSaver saver(debug);
debug.nospace(); debug.nospace();
const QWidget *widget = attributes.widget; debug << '[';
if (const QWidget *widget = attributes.widget) {
const QMetaObject *qtMo = qt_getEnumMetaObject(Qt::WA_AttributeCount); const QMetaObject *qtMo = qt_getEnumMetaObject(Qt::WA_AttributeCount);
const QMetaEnum me = qtMo->enumerator(qtMo->indexOfEnumerator("WidgetAttribute")); const QMetaEnum me = qtMo->enumerator(qtMo->indexOfEnumerator("WidgetAttribute"));
debug << '[';
int count = 0; int count = 0;
for (int a = 0; a < Qt::WA_AttributeCount; ++a) { for (int a = 0; a < Qt::WA_AttributeCount; ++a) {
if (widget->testAttribute(static_cast<Qt::WidgetAttribute>(a))) { if (widget->testAttribute(static_cast<Qt::WidgetAttribute>(a))) {
@ -13226,6 +13226,7 @@ QDebug operator<<(QDebug debug, const WidgetAttributes &attributes)
debug << me.valueToKey(a); debug << me.valueToKey(a);
} }
} }
}
debug << ']'; debug << ']';
return debug; return debug;
} }