Eeschema: protect lib symbols against duplicate field names.
If a field name is already in use, try to rename the new field name (adding the suffix "_1" or "_2" or ... ) This is especially critical when a non mandatory field has the same name as a mandatory field (was crashing before) Fixes #8081 https://gitlab.com/kicad/code/kicad/issues/8081
This commit is contained in:
parent
90abc8ba8b
commit
6499b5f296
|
@ -844,8 +844,30 @@ LIB_FIELD* SCH_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_PART>& aSymbol )
|
|||
}
|
||||
else
|
||||
{
|
||||
// At this point, a user field is read.
|
||||
existingField = aSymbol->FindField( field->GetCanonicalName() );
|
||||
|
||||
#if 1 // Enable it to modify the name of the field to add if already existing
|
||||
// Disable it to skip the field having the same name as previous field
|
||||
if( existingField )
|
||||
{
|
||||
// We cannot handle 2 fields with the same name, so because the field name
|
||||
// is already in use, try to build a new name (oldname_x)
|
||||
wxString base_name = field->GetCanonicalName();
|
||||
|
||||
// Arbitrary limit 10 attempts to find a new name
|
||||
for( int ii = 1; ii < 10 && existingField ; ii++ )
|
||||
{
|
||||
wxString newname = base_name;
|
||||
newname << '_' << ii;
|
||||
|
||||
existingField = aSymbol->FindField( newname );
|
||||
|
||||
if( !existingField ) // the modified name is not found, use it
|
||||
field->SetName( newname );
|
||||
}
|
||||
}
|
||||
|
||||
if( !existingField )
|
||||
{
|
||||
aSymbol->AddDrawItem( field.get(), false );
|
||||
|
@ -853,8 +875,8 @@ LIB_FIELD* SCH_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_PART>& aSymbol )
|
|||
}
|
||||
else
|
||||
{
|
||||
*existingField = *field;
|
||||
return existingField;
|
||||
// We cannot handle 2 fields with the same name, so skip this one
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue