diff --git a/eeschema/tools/symbol_editor_pin_tool.cpp b/eeschema/tools/symbol_editor_pin_tool.cpp index fd836509d5..9a8568129b 100644 --- a/eeschema/tools/symbol_editor_pin_tool.cpp +++ b/eeschema/tools/symbol_editor_pin_tool.cpp @@ -138,9 +138,13 @@ bool SYMBOL_EDITOR_PIN_TOOL::EditPinProperties( LIB_PIN* aPin ) { LIB_PINS pinList; aPin->GetParent()->GetPins( pinList ); - std::vector got_unit( aPin->GetParent()->GetUnitCount() ); - got_unit[static_cast(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 got_unit( aPin->GetParent()->GetUnitCount()+1 ); + + got_unit[static_cast(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( other->GetUnit() ) - 1] ) + if( got_unit[static_cast( 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( other->GetUnit() ) - 1] = true; + got_unit[static_cast( other->GetUnit() )] = true; } } }