OSDN Git Service

do not attempt to draw points from QPaintEngine::drawPolygon() if their count is...
authorIvailo Monev <xakepa10@gmail.com>
Wed, 12 Oct 2022 21:14:23 +0000 (00:14 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Wed, 12 Oct 2022 21:14:23 +0000 (00:14 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/gui/painting/qpaintengine.cpp

index 5fc7835..4f22bd3 100644 (file)
@@ -258,15 +258,17 @@ static QPaintEngine *qt_polygon_recursion = 0;
 */
 void QPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
 {
-    Q_ASSERT_X(qt_polygon_recursion != this, "QPaintEngine::drawPolygon",
-               "At least one drawPolygon function must be implemented");
-    qt_polygon_recursion = this;
-    QSTACKARRAY(QPoint, fp, pointCount);
-    for (int i = 0; i < pointCount; ++i) {
-        fp[i] = points[i].toPoint();
+    if (Q_LIKELY(pointCount > 0)) {
+        Q_ASSERT_X(qt_polygon_recursion != this, "QPaintEngine::drawPolygon",
+                   "At least one drawPolygon function must be implemented");
+        qt_polygon_recursion = this;
+        QSTACKARRAY(QPoint, fp, pointCount);
+        for (int i = 0; i < pointCount; ++i) {
+            fp[i] = points[i].toPoint();
+        }
+        drawPolygon(fp, pointCount, mode);
+        qt_polygon_recursion = 0;
     }
-    drawPolygon(fp, pointCount, mode);
-    qt_polygon_recursion = 0;
 }
 
 /*!
@@ -279,15 +281,17 @@ void QPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDra
 */
 void QPaintEngine::drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode)
 {
-    Q_ASSERT_X(qt_polygon_recursion != this, "QPaintEngine::drawPolygon",
-               "At least one drawPolygon function must be implemented");
-    qt_polygon_recursion = this;
-    QSTACKARRAY(QPointF, fp, pointCount);
-    for (int i = 0; i < pointCount; ++i) {
-        fp[i] = points[i];
+    if (Q_LIKELY(pointCount > 0)) {
+        Q_ASSERT_X(qt_polygon_recursion != this, "QPaintEngine::drawPolygon",
+                   "At least one drawPolygon function must be implemented");
+        qt_polygon_recursion = this;
+        QSTACKARRAY(QPointF, fp, pointCount);
+        for (int i = 0; i < pointCount; ++i) {
+            fp[i] = points[i];
+        }
+        drawPolygon(fp, pointCount, mode);
+        qt_polygon_recursion = 0;
     }
-    drawPolygon(fp, pointCount, mode);
-    qt_polygon_recursion = 0;
 }
 
 /*!