Don't crash on empty SHAPE_LINE_CHAINs.

Fixes https://gitlab.com/kicad/code/kicad/issues/12407
This commit is contained in:
Jeff Young 2022-09-13 13:27:39 +01:00
parent 0a5ca5b485
commit fc74de81fb
1 changed files with 12 additions and 0 deletions

View File

@ -1788,6 +1788,12 @@ SHAPE_LINE_CHAIN& SHAPE_LINE_CHAIN::Simplify( bool aRemoveColinear )
const VECTOR2I SHAPE_LINE_CHAIN::NearestPoint( const VECTOR2I& aP, const VECTOR2I SHAPE_LINE_CHAIN::NearestPoint( const VECTOR2I& aP,
bool aAllowInternalShapePoints ) const bool aAllowInternalShapePoints ) const
{ {
if( PointCount() == 0 )
{
// The only right answer here is "don't crash".
return { 0, 0 };
}
int min_d = INT_MAX; int min_d = INT_MAX;
int nearest = 0; int nearest = 0;
@ -1839,6 +1845,12 @@ const VECTOR2I SHAPE_LINE_CHAIN::NearestPoint( const VECTOR2I& aP,
const VECTOR2I SHAPE_LINE_CHAIN::NearestPoint( const SEG& aSeg, int& dist ) const const VECTOR2I SHAPE_LINE_CHAIN::NearestPoint( const SEG& aSeg, int& dist ) const
{ {
if( PointCount() == 0 )
{
// The only right answer here is "don't crash".
return { 0, 0 };
}
int nearest = 0; int nearest = 0;
dist = INT_MAX; dist = INT_MAX;