Edit pin number: fix a crash when a pin is common to all units (i.e. having a unit id = 0)

Fixes #8824
https://gitlab.com/kicad/code/kicad/issues/8824
This commit is contained in:
jean-pierre charras 2021-07-20 16:49:32 +02:00
parent bf80b9c04c
commit bff0307ac0
1 changed files with 8 additions and 4 deletions

View File

@ -138,9 +138,13 @@ bool SYMBOL_EDITOR_PIN_TOOL::EditPinProperties( LIB_PIN* aPin )
{
LIB_PINS pinList;
aPin->GetParent()->GetPins( pinList );
std::vector<bool> got_unit( aPin->GetParent()->GetUnitCount() );
got_unit[static_cast<size_t>(aPin->GetUnit()) - 1] = true;
// a pin can have a unit id = 0 (common to all units) to unit count
// So we need a buffer size = GetUnitCount()+1 to store a value in a vector
// when using the unit id of a pin as index
std::vector<bool> got_unit( aPin->GetParent()->GetUnitCount()+1 );
got_unit[static_cast<size_t>(aPin->GetUnit())] = true;
for( LIB_PIN* other : pinList )
{
@ -150,7 +154,7 @@ bool SYMBOL_EDITOR_PIN_TOOL::EditPinProperties( LIB_PIN* aPin )
/// Only change one pin per unit to allow stacking pins
/// If you change all units on the position, then pins are not
/// uniquely editable
if( got_unit[static_cast<size_t>( other->GetUnit() ) - 1] )
if( got_unit[static_cast<size_t>( other->GetUnit() )] )
continue;
if( other->GetPosition() == original_pin.GetPosition()
@ -185,7 +189,7 @@ bool SYMBOL_EDITOR_PIN_TOOL::EditPinProperties( LIB_PIN* aPin )
other->SetNumberTextSize( aPin->GetNumberTextSize() );
other->SetModified();
got_unit[static_cast<size_t>( other->GetUnit() ) - 1] = true;
got_unit[static_cast<size_t>( other->GetUnit() )] = true;
}
}
}