From a928299ae0e7a951bdf5c772f4b036d293bc0ef2 Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Thu, 22 Feb 2024 21:31:57 +0100 Subject: [PATCH] Legacy libraries: De-duplicate field names on load Fixes https://gitlab.com/kicad/code/kicad/-/issues/16902 (cherry picked from commit 07ab18a1e62c1d7e1ccab1b1b71db5279362d582) --- .../sch_io_kicad_legacy_lib_cache.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.cpp b/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.cpp index d8ee82cb46..92871cf22d 100644 --- a/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.cpp +++ b/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.cpp @@ -670,7 +670,20 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::loadField( std::unique_ptr& aSym } else { - parseQuotedString( field->m_name, aReader, line, &line, true ); // Optional. + wxString fieldName = wxEmptyString; + parseQuotedString( fieldName, aReader, line, &line, true ); // Optional. + + if( fieldName.IsEmpty() ) + return; + + wxString candidateFieldName = fieldName; + int suffix = 0; + + //Deduplicate field name + while( aSymbol->FindField( candidateFieldName ) != nullptr ) + candidateFieldName = wxString::Format( "%s_%d", fieldName, ++suffix ); + + field->m_name = candidateFieldName; } }