SHAPE_LINE_CHAIN::Replace Don't call front() or back() if empty
Fixes https://gitlab.com/kicad/code/kicad/-/issues/8949
This commit is contained in:
parent
02e7d9f809
commit
d9cf939ba1
|
@ -478,11 +478,25 @@ void SHAPE_LINE_CHAIN::Replace( int aStartIndex, int aEndIndex, const SHAPE_LINE
|
||||||
|
|
||||||
SHAPE_LINE_CHAIN newLine = aLine;
|
SHAPE_LINE_CHAIN newLine = aLine;
|
||||||
|
|
||||||
|
// Zero points to add?
|
||||||
|
if( newLine.PointCount() == 0 )
|
||||||
|
{
|
||||||
|
Remove( aStartIndex, aEndIndex );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove coincident points in the new line
|
// Remove coincident points in the new line
|
||||||
if( newLine.m_points.front() == m_points[aStartIndex] )
|
if( newLine.m_points.front() == m_points[aStartIndex] )
|
||||||
{
|
{
|
||||||
aStartIndex++;
|
aStartIndex++;
|
||||||
newLine.Remove( 0 );
|
newLine.Remove( 0 );
|
||||||
|
|
||||||
|
// Zero points to add?
|
||||||
|
if( newLine.PointCount() == 0 )
|
||||||
|
{
|
||||||
|
Remove( aStartIndex, aEndIndex );
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( newLine.m_points.back() == m_points[aEndIndex] && aEndIndex > 0 )
|
if( newLine.m_points.back() == m_points[aEndIndex] && aEndIndex > 0 )
|
||||||
|
@ -493,7 +507,8 @@ void SHAPE_LINE_CHAIN::Replace( int aStartIndex, int aEndIndex, const SHAPE_LINE
|
||||||
|
|
||||||
Remove( aStartIndex, aEndIndex );
|
Remove( aStartIndex, aEndIndex );
|
||||||
|
|
||||||
if( !newLine.PointCount() )
|
// Zero points to add?
|
||||||
|
if( newLine.PointCount() == 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// The total new arcs index is added to the new arc indices
|
// The total new arcs index is added to the new arc indices
|
||||||
|
|
|
@ -290,5 +290,34 @@ BOOST_AUTO_TEST_CASE( NearestPointPt )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Test SHAPE_LINE_CHAIN::Replace( SHAPE_LINE_CHAIN )
|
||||||
|
BOOST_AUTO_TEST_CASE( ReplaceChain )
|
||||||
|
{
|
||||||
|
BOOST_TEST_INFO( "8949 crash" );
|
||||||
|
|
||||||
|
std::vector<VECTOR2I> linePts = {
|
||||||
|
{ 206000000, 140110000 }, { 192325020, 140110000 }, { 192325020, 113348216 },
|
||||||
|
{ 192251784, 113274980 }, { 175548216, 113274980 }, { 175474980, 113348216 },
|
||||||
|
{ 175474980, 136694980 }, { 160774511, 121994511 }, { 160774511, 121693501 },
|
||||||
|
{ 160086499, 121005489 }, { 159785489, 121005489 }, { 159594511, 120814511 },
|
||||||
|
{ 160086499, 120814511 }, { 160774511, 120126499 }, { 160774511, 119153501 },
|
||||||
|
{ 160086499, 118465489 }, { 159113501, 118465489 }, { 158425489, 119153501 },
|
||||||
|
{ 158425489, 119645489 }, { 157325020, 118545020 }, { 157325020, 101925020 },
|
||||||
|
{ 208674980, 101925020 }, { 208674980, 145474980 }, { 192325020, 145474980 },
|
||||||
|
{ 192325020, 140110000 }
|
||||||
|
};
|
||||||
|
|
||||||
|
SHAPE_LINE_CHAIN baseChain( linePts, false );
|
||||||
|
baseChain.SetWidth( 250000 );
|
||||||
|
BOOST_CHECK_EQUAL( baseChain.PointCount(), linePts.size() );
|
||||||
|
|
||||||
|
SHAPE_LINE_CHAIN replaceChain( { VECTOR2I( 192325020, 140110000 ) }, false );
|
||||||
|
BOOST_CHECK_EQUAL( replaceChain.PointCount(), 1 );
|
||||||
|
|
||||||
|
baseChain.Replace( 1, 23, replaceChain );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( baseChain.PointCount(), linePts.size() - ( 23 - 1 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
Loading…
Reference in New Issue