From 73a8d2a9d57fabef72db8c102c616d932c3beab3 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Sat, 23 Jun 2018 02:02:49 +0200 Subject: [PATCH] OPENGL GAL: Fixed the iteration condition when drawing triangulated polyset The loop used an incorrect variable size as the loop limit, occasionally causing out of bounds accesses. Fixes: lp:1778288 * https://bugs.launchpad.net/kicad/+bug/1778288 --- common/gal/opengl/opengl_gal.cpp | 2 +- include/geometry/shape_poly_set.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index d2ae49977f..2aeec34798 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -805,7 +805,7 @@ void OPENGL_GAL::drawTriangulatedPolyset( const SHAPE_POLY_SET& aPolySet ) if( isFillEnabled ) { - for( int j = 0; j < aPolySet.OutlineCount(); ++j ) + for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j ) { auto triPoly = aPolySet.TriangulatedPolygon( j ); diff --git a/include/geometry/shape_poly_set.h b/include/geometry/shape_poly_set.h index 00b56f786a..8714c5d13c 100644 --- a/include/geometry/shape_poly_set.h +++ b/include/geometry/shape_poly_set.h @@ -548,6 +548,9 @@ class SHAPE_POLY_SET : public SHAPE */ bool IsSelfIntersecting(); + ///> Returns the number of triangulated polygons + unsigned int TriangulatedPolyCount() const { return m_triangulatedPolys.size(); } + ///> Returns the number of outlines in the set int OutlineCount() const { return m_polys.size(); }