PNS: validate SHAPE_LINE_CHAIN before accessing its segments

(cherry picked from commit 4d73cfb8a1)
This commit is contained in:
Maciej Suminski 2018-11-25 23:40:22 +01:00
parent 50eedcf0b3
commit 1b1a3763d2
2 changed files with 14 additions and 3 deletions

View File

@ -339,6 +339,7 @@ void LINE::ShowLinks() const
wxLogTrace( "PNS", "seg %d: %p\n", i, m_segmentRefs[i] );
}
SHAPE_LINE_CHAIN dragCornerInternal( const SHAPE_LINE_CHAIN& aOrigin, const VECTOR2I& aP )
{
OPT<SHAPE_LINE_CHAIN> picked;
@ -362,14 +363,21 @@ SHAPE_LINE_CHAIN dragCornerInternal( const SHAPE_LINE_CHAIN& aOrigin, const VECT
SHAPE_LINE_CHAIN paths[2];
DIRECTION_45 dirs[2];
DIRECTION_45 d_prev = ( i > 0 ? DIRECTION_45( aOrigin.CSegment( i-1 ) ) : DIRECTION_45() );
int dirCount = 0;
for( int j = 0; j < 2; j++ )
{
paths[j] = d_start.BuildInitialTrace( p_start, aP, j );
dirs[j] = DIRECTION_45( paths[j].CSegment( 0 ) );
if( paths[j].SegmentCount() < 1 )
continue;
assert( dirCount < sizeof( dirs ) / sizeof( dirs[0] ) );
dirs[dirCount] = DIRECTION_45( paths[j].CSegment( 0 ) );
++dirCount;
}
for( int j = 0; j < 2; j++ )
for( int j = 0; j < dirCount; j++ )
{
if( dirs[j] == d_start )
{
@ -381,7 +389,7 @@ SHAPE_LINE_CHAIN dragCornerInternal( const SHAPE_LINE_CHAIN& aOrigin, const VECT
if( picked )
break;
for( int j = 0; j < 2; j++ )
for( int j = 0; j < dirCount; j++ )
{
if( dirs[j].IsObtuse( d_prev ) )
{

View File

@ -243,6 +243,9 @@ bool LINE_PLACER::reduceTail( const VECTOR2I& aEnd )
// the direction of the segment to be replaced
SHAPE_LINE_CHAIN replacement = dir.BuildInitialTrace( s.A, aEnd );
if( replacement.SegmentCount() < 1 )
continue;
LINE tmp( m_tail, replacement );
if( m_currentNode->CheckColliding( &tmp, ITEM::ANY_T ) )