summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2011-02-22 13:44:58 (GMT)
committerSamuel Rødal <samuel.rodal@nokia.com>2011-02-22 13:54:12 (GMT)
commit9d019830169289a3aa00e8baca9c320963904993 (patch)
tree03e2a689b96cca552037bc88411410c0e8e7e5b4
parentdb9925a187a9ad395ba2cabf23487b9a0e09c67c (diff)
downloadQt-9d019830169289a3aa00e8baca9c320963904993.zip
Qt-9d019830169289a3aa00e8baca9c320963904993.tar.gz
Qt-9d019830169289a3aa00e8baca9c320963904993.tar.bz2
Prevent infinite loop in raster engine on zero dash pattern length.
Task-number: QTBUG-17053 Reviewed-by: Kim
-rw-r--r--src/gui/painting/qpaintengine_raster.cpp7
-rw-r--r--tests/auto/qpainter/tst_qpainter.cpp22
2 files changed, 29 insertions, 0 deletions
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index 682731a..ba618ea 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -3706,6 +3706,13 @@ void QRasterPaintEnginePrivate::rasterizeLine_dashed(QLineF line,
const bool squareCap = (pen.capStyle() == Qt::SquareCap);
const QVector<qreal> pattern = pen.dashPattern();
+ qreal patternLength = 0;
+ for (int i = 0; i < pattern.size(); ++i)
+ patternLength += pattern.at(i);
+
+ if (patternLength <= 0)
+ return;
+
qreal length = line.length();
Q_ASSERT(length > 0);
while (length > 0) {
diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp
index 4cf64f1..c9eca89 100644
--- a/tests/auto/qpainter/tst_qpainter.cpp
+++ b/tests/auto/qpainter/tst_qpainter.cpp
@@ -258,6 +258,8 @@ private slots:
void QTBUG14614_gradientCacheRaceCondition();
void drawTextOpacity();
+ void QTBUG17053_zeroDashPattern();
+
private:
void fillData();
void setPenColor(QPainter& p);
@@ -4601,6 +4603,26 @@ void tst_QPainter::drawTextOpacity()
QCOMPARE(image, copy);
}
+void tst_QPainter::QTBUG17053_zeroDashPattern()
+{
+ QImage image(32, 32, QImage::Format_RGB32);
+ image.fill(0xffffffff);
+
+ QImage original = image;
+
+ QVector<qreal> pattern;
+ pattern << qreal(0) << qreal(0);
+
+ QPainter p(&image);
+ QPen pen(Qt::black, 2.0);
+ pen.setDashPattern(pattern);
+
+ p.setPen(pen);
+ p.drawLine(0, 0, image.width(), image.height());
+
+ QCOMPARE(image, original);
+}
+
QTEST_MAIN(tst_QPainter)
#include "tst_qpainter.moc"