From dfaa43331afd8b6180fbe2f13e88f576ff64b7ad Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 5 Mar 2025 13:47:24 +0100 Subject: [PATCH] QPen: QDebug-stream Pen{,Join}Style etc as enums MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Coverity complained that PEN_STYLES[p.style()] may be an out-of-bounds access, and it is, since setPen() doesn't sanitze its argument and we have Qt::PenStyle::MPenStyle as an extra (hidden) enumerator that Coverity doesn't know we never use. Instead of fixing the issue with the array lookup, realize that all three enums are Q_ENUM_NS in namespace Qt and use the "magic" QDebug stream operator for Q_ENUMs to do the numeric -> string conversion, making invalid enum values SEP. Not picking to older branches, since it's changing the output. [ChangeLog][QtGui][QPen] The debug stream operator now prints the names of capStyle() and joinStyle() (was: numerical values). Coverity-Id: 390701 Change-Id: Icc593fac3ab02c56a4b39b2a7c8a5d423d626ce3 Reviewed-by: Volker Hilsheimer Reviewed-by: Øystein Heskestad --- src/gui/painting/qpen.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/gui/painting/qpen.cpp b/src/gui/painting/qpen.cpp index d974c18728a..b2242087d91 100644 --- a/src/gui/painting/qpen.cpp +++ b/src/gui/painting/qpen.cpp @@ -1014,20 +1014,10 @@ QDataStream &operator>>(QDataStream &s, QPen &p) #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QPen &p) { - const char *PEN_STYLES[] = { - "NoPen", - "SolidLine", - "DashLine", - "DotLine", - "DashDotLine", - "DashDotDotLine", - "CustomDashLine" - }; - QDebugStateSaver saver(dbg); dbg.nospace() << "QPen(" << p.width() << ',' << p.brush() - << ',' << PEN_STYLES[p.style()] << ',' << int(p.capStyle()) - << ',' << int(p.joinStyle()) << ',' << p.dashPattern() + << ',' << p.style() << ',' << p.capStyle() + << ',' << p.joinStyle() << ',' << p.dashPattern() << ',' << p.dashOffset() << ',' << p.miterLimit() << ')'; return dbg;