From 9f69247af12608af6c931b0ebab022a66823a31f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 31 May 2022 16:49:31 +0200 Subject: [PATCH] QBrush: port from array of char[24] to qOffsetStringArray() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QOffsetStringArray has a more compact representation and silences warnings from GCC 12 builds with asan and ubsan sanitizers enabled: qbrush.cpp: In function ‘QDebug operator<<(QDebug, const QBrush&)’: qbrush.cpp:978:77: error: array subscript [0, 31] is outside array bounds of ‘const char [25][24]’ [-Werror=array-bounds] 978 | dbg.nospace() << "QBrush(" << b.color() << ',' << BRUSH_STYLES[b.style()] << ')'; | ~~~~~~~~~~~~~~~~~~~~~~^ qbrush.cpp:954:23: note: while referencing ‘BRUSH_STYLES’ 954 | static const char BRUSH_STYLES[][24] = { | ^~~~~~~~~~~~ cc1plus: all warnings being treated as errors Task-number: QTBUG-103923 Change-Id: I5f81f516894e57b47783e2d89489a676b657fdb7 Reviewed-by: Thiago Macieira Reviewed-by: Mårten Nordheim (cherry picked from commit 6376b1c5a708ddb1a82e81cbc7ce4df159ba565b) Reviewed-by: Qt Cherry-pick Bot --- src/gui/painting/qbrush.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index 7b2d91e7727..384da05896b 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -54,6 +54,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -985,7 +986,7 @@ bool QBrush::operator==(const QBrush &b) const */ QDebug operator<<(QDebug dbg, const QBrush &b) { - static const char BRUSH_STYLES[][24] = { + static constexpr auto BRUSH_STYLES = qOffsetStringArray( "NoBrush", "SolidPattern", "Dense1Pattern", @@ -1006,7 +1007,7 @@ QDebug operator<<(QDebug dbg, const QBrush &b) "ConicalGradientPattern", "", "", "", "", "", "", "TexturePattern" // 24 - }; + ); QDebugStateSaver saver(dbg); dbg.nospace() << "QBrush(" << b.color() << ',' << BRUSH_STYLES[b.style()] << ')';