summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2025-03-05 13:47:24 +0100
committerMarc Mutz <[email protected]>2025-03-06 22:57:23 +0100
commitdfaa43331afd8b6180fbe2f13e88f576ff64b7ad (patch)
treee1f6514449a4b228ef5d4ac694163316ec6f8eb2
parent7a32a2238f52217bc4f0dc4c9620a2a2d350a1ca (diff)
QPen: QDebug-stream Pen{,Join}Style etc as enums
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 <[email protected]> Reviewed-by: Øystein Heskestad <[email protected]>
-rw-r--r--src/gui/painting/qpen.cpp14
1 files 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;