GAL: Check that polygons have at least 3 points

This resolves a crash when passing an empty polygon and alerts debug
users to possible generation cases when bad polygons are created.

Thanks for Frans Zellman
(https://gitlab.com/kicad/code/kicad/-/merge_requests/365) for
identifying the issue.
This commit is contained in:
Seth Hillbrand 2020-08-21 09:36:41 -07:00
parent cd51785173
commit 7fc222db98
2 changed files with 8 additions and 4 deletions

View File

@ -1117,6 +1117,8 @@ void CAIRO_GAL_BASE::blitCursor( wxMemoryDC& clientDC )
void CAIRO_GAL_BASE::drawPoly( const std::deque<VECTOR2D>& aPointList )
{
wxCHECK( aPointList.size() > 2, /* void */ );
// Iterate over the point list and draw the segments
std::deque<VECTOR2D>::const_iterator it = aPointList.begin();
@ -1140,6 +1142,8 @@ void CAIRO_GAL_BASE::drawPoly( const std::deque<VECTOR2D>& aPointList )
void CAIRO_GAL_BASE::drawPoly( const VECTOR2D aPointList[], int aListSize )
{
wxCHECK( aListSize > 2, /* void */ );
// Iterate over the point list and draw the segments
const VECTOR2D* ptr = aPointList;
@ -1162,8 +1166,7 @@ void CAIRO_GAL_BASE::drawPoly( const VECTOR2D aPointList[], int aListSize )
void CAIRO_GAL_BASE::drawPoly( const SHAPE_LINE_CHAIN& aLineChain )
{
if( aLineChain.PointCount() < 2 )
return;
wxCHECK( aLineChain.PointCount() > 2, /* void */ );
syncLineWidth();

View File

@ -978,6 +978,7 @@ void OPENGL_GAL::DrawPolyline( const SHAPE_LINE_CHAIN& aLineChain )
void OPENGL_GAL::DrawPolygon( const std::deque<VECTOR2D>& aPointList )
{
wxCHECK( aPointList.size() > 2, /* void */ );
auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aPointList.size()] );
GLdouble* ptr = points.get();
@ -994,6 +995,7 @@ void OPENGL_GAL::DrawPolygon( const std::deque<VECTOR2D>& aPointList )
void OPENGL_GAL::DrawPolygon( const VECTOR2D aPointList[], int aListSize )
{
wxCHECK( aListSize > 2, /* void */ );
auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aListSize] );
GLdouble* target = points.get();
const VECTOR2D* src = aPointList;
@ -1092,8 +1094,7 @@ void OPENGL_GAL::DrawPolygon( const SHAPE_POLY_SET& aPolySet )
void OPENGL_GAL::DrawPolygon( const SHAPE_LINE_CHAIN& aPolygon )
{
if( aPolygon.SegmentCount() == 0 )
return;
wxCHECK( aPolygon.PointCount() > 2, /* void */ );
const int pointCount = aPolygon.SegmentCount() + 1;
std::unique_ptr<GLdouble[]> points( new GLdouble[3 * pointCount] );