Coverity tweaks.

This commit is contained in:
Jeff Young 2025-07-28 11:22:55 +01:00
parent 59caea4344
commit 325570eeec
9 changed files with 66 additions and 76 deletions

View File

@ -48,12 +48,8 @@ public:
const wxString& GetBoardFile() const { return m_boardFile; } const wxString& GetBoardFile() const { return m_boardFile; }
void SetBoardFile( const wxString& aFile ) { m_boardFile = aFile; } void SetBoardFile( const wxString& aFile ) { m_boardFile = aFile; }
void SetFields( nlohmann::ordered_map<wxString, wxString>& aFields )
{
m_fields = std::move( aFields );
}
const nlohmann::ordered_map<wxString, wxString>& GetFields() const { return m_fields; } const nlohmann::ordered_map<wxString, wxString>& GetFields() const { return m_fields; }
nlohmann::ordered_map<wxString, wxString>& GetFields() { return m_fields; }
DESIGN_BLOCK() = default; DESIGN_BLOCK() = default;

View File

@ -325,8 +325,6 @@ DESIGN_BLOCK* DESIGN_BLOCK_IO::DesignBlockLoad( const wxString& aLibraryPath,
if( dbMetadata.contains( "keywords" ) ) if( dbMetadata.contains( "keywords" ) )
newDB->SetKeywords( dbMetadata["keywords"] ); newDB->SetKeywords( dbMetadata["keywords"] );
nlohmann::ordered_map<wxString, wxString> fields;
// Read the "fields" object from the JSON // Read the "fields" object from the JSON
if( dbMetadata.contains( "fields" ) ) if( dbMetadata.contains( "fields" ) )
{ {
@ -335,10 +333,8 @@ DESIGN_BLOCK* DESIGN_BLOCK_IO::DesignBlockLoad( const wxString& aLibraryPath,
wxString name = wxString::FromUTF8( item.key() ); wxString name = wxString::FromUTF8( item.key() );
wxString value = wxString::FromUTF8( item.value().get<std::string>() ); wxString value = wxString::FromUTF8( item.value().get<std::string>() );
fields[name] = value; newDB->GetFields()[name] = value;
} }
newDB->SetFields( fields );
} }
} }
catch( ... ) catch( ... )

View File

@ -194,7 +194,7 @@ bool DIALOG_DESIGN_BLOCK_PROPERTIES::TransferDataFromGrid()
if( !m_fieldsGrid->CommitPendingChanges() ) if( !m_fieldsGrid->CommitPendingChanges() )
return false; return false;
nlohmann::ordered_map<wxString, wxString> newFields; m_designBlock->GetFields().clear();
for( int row = 0; row < m_fieldsGrid->GetNumberRows(); row++ ) for( int row = 0; row < m_fieldsGrid->GetNumberRows(); row++ )
{ {
@ -202,17 +202,15 @@ bool DIALOG_DESIGN_BLOCK_PROPERTIES::TransferDataFromGrid()
fieldName.Replace( wxT( "\n" ), wxT( "" ), true ); // strip all newlines fieldName.Replace( wxT( "\n" ), wxT( "" ), true ); // strip all newlines
fieldName.Replace( wxT( " " ), wxT( " " ), true ); // double space to single fieldName.Replace( wxT( " " ), wxT( " " ), true ); // double space to single
if( newFields.count( fieldName ) ) if( m_designBlock->GetFields().count( fieldName ) )
{ {
wxMessageBox( _( "Duplicate fields are not allowed." ) ); wxMessageBox( _( "Duplicate fields are not allowed." ) );
return false; return false;
} }
newFields[fieldName] = m_fieldsGrid->GetCellValue( row, 1 ); m_designBlock->GetFields()[fieldName] = m_fieldsGrid->GetCellValue( row, 1 );
} }
m_designBlock->SetFields( newFields );
return true; return true;
} }

View File

@ -194,10 +194,13 @@ void DIALOG_CONFIG_EQUFILES::OnRemoveFiles( wxCommandEvent& event )
wxArrayInt selections; wxArrayInt selections;
m_filesListBox->GetSelections( selections ); m_filesListBox->GetSelections( selections );
if( !selections.empty() )
{
std::sort( selections.begin(), selections.end() ); std::sort( selections.begin(), selections.end() );
for( int ii = selections.GetCount()-1; ii >= 0; ii-- ) for( int ii = (int) selections.GetCount() - 1; ii >= 0; ii-- )
m_filesListBox->Delete( selections[ii] ); m_filesListBox->Delete( selections[ii] );
}
} }

View File

@ -1041,9 +1041,10 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnPageChanging( wxBookCtrlEvent& aEvent )
void DIALOG_LIB_SYMBOL_PROPERTIES::OnBtnCreateJumperPinGroup( wxCommandEvent& aEvent ) void DIALOG_LIB_SYMBOL_PROPERTIES::OnBtnCreateJumperPinGroup( wxCommandEvent& aEvent )
{ {
wxArrayInt selections; wxArrayInt selections;
int n = m_listAvailablePins->GetSelections( selections ); m_listAvailablePins->GetSelections( selections );
wxCHECK( n > 0, /* void */ );
if( !selections.empty() )
{
m_listJumperPinGroups->Freeze(); m_listJumperPinGroups->Freeze();
m_listAvailablePins->Freeze(); m_listAvailablePins->Freeze();
@ -1054,27 +1055,28 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnBtnCreateJumperPinGroup( wxCommandEvent& aE
{ {
group << m_listAvailablePins->GetString( idx ); group << m_listAvailablePins->GetString( idx );
if( ++i < n ) if( ++i < selections.Count() )
group << ", "; group << ", ";
} }
for( int idx = selections.size() - 1; idx >= 0; --idx ) for( int idx = (int) selections.size() - 1; idx >= 0; --idx )
m_listAvailablePins->Delete( selections[idx] ); m_listAvailablePins->Delete( selections[idx] );
m_listJumperPinGroups->AppendString( group ); m_listJumperPinGroups->AppendString( group );
m_listJumperPinGroups->Thaw(); m_listJumperPinGroups->Thaw();
m_listAvailablePins->Thaw(); m_listAvailablePins->Thaw();
}
} }
void DIALOG_LIB_SYMBOL_PROPERTIES::OnBtnRemoveJumperPinGroup( wxCommandEvent& aEvent ) void DIALOG_LIB_SYMBOL_PROPERTIES::OnBtnRemoveJumperPinGroup( wxCommandEvent& aEvent )
{ {
wxArrayInt selections; wxArrayInt selections;
m_listJumperPinGroups->GetSelections( selections );
if( m_listJumperPinGroups->GetSelections( selections ) <= 0 ) if( !selections.empty() )
return; {
m_listJumperPinGroups->Freeze(); m_listJumperPinGroups->Freeze();
m_listAvailablePins->Freeze(); m_listAvailablePins->Freeze();
@ -1089,11 +1091,12 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnBtnRemoveJumperPinGroup( wxCommandEvent& aE
} }
} }
for( int idx = selections.size() - 1; idx >= 0; --idx ) for( int idx = (int) selections.size() - 1; idx >= 0; --idx )
m_listJumperPinGroups->Delete( selections[idx] ); m_listJumperPinGroups->Delete( selections[idx] );
m_listJumperPinGroups->Thaw(); m_listJumperPinGroups->Thaw();
m_listAvailablePins->Thaw(); m_listAvailablePins->Thaw();
}
} }

View File

@ -98,19 +98,14 @@ bool SCH_EDIT_FRAME::SaveSheetAsDesignBlock( const wxString& aLibraryName, SCH_S
blk.SetLibId( LIB_ID( aLibraryName, fn.GetName() ) ); blk.SetLibId( LIB_ID( aLibraryName, fn.GetName() ) );
// Copy all fields from the sheet to the design block // Copy all fields from the sheet to the design block
std::vector<SCH_FIELD>& shFields = aSheetPath.Last()->GetFields(); for( SCH_FIELD& field : aSheetPath.Last()->GetFields() )
nlohmann::ordered_map<wxString, wxString> dbFields;
for( SCH_FIELD& f : shFields )
{ {
if( f.GetId() == FIELD_T::SHEET_NAME || f.GetId() == FIELD_T::SHEET_FILENAME ) if( field.GetId() == FIELD_T::SHEET_NAME || field.GetId() == FIELD_T::SHEET_FILENAME )
continue; continue;
dbFields[f.GetCanonicalName()] = f.GetText(); blk.GetFields()[field.GetCanonicalName()] = field.GetText();
} }
blk.SetFields( dbFields );
DIALOG_DESIGN_BLOCK_PROPERTIES dlg( this, &blk ); DIALOG_DESIGN_BLOCK_PROPERTIES dlg( this, &blk );
if( dlg.ShowModal() != wxID_OK ) if( dlg.ShowModal() != wxID_OK )
@ -191,19 +186,14 @@ bool SCH_EDIT_FRAME::SaveSheetToDesignBlock( const LIB_ID& aLibId, SCH_SHEET_PAT
// Copy all fields from the sheet to the design block. // Copy all fields from the sheet to the design block.
// Note: this will overwrite any existing fields in the design block, but // Note: this will overwrite any existing fields in the design block, but
// will leave extra fields not in this source sheet alone. // will leave extra fields not in this source sheet alone.
std::vector<SCH_FIELD>& shFields = aSheetPath.Last()->GetFields(); for( SCH_FIELD& field : aSheetPath.Last()->GetFields() )
nlohmann::ordered_map<wxString, wxString> dbFields = blk->GetFields();
for( SCH_FIELD& f : shFields )
{ {
if( f.GetId() == FIELD_T::SHEET_NAME || f.GetId() == FIELD_T::SHEET_FILENAME ) if( field.GetId() == FIELD_T::SHEET_NAME || field.GetId() == FIELD_T::SHEET_FILENAME )
continue; continue;
dbFields[f.GetCanonicalName()] = f.GetText(); blk->GetFields()[field.GetCanonicalName()] = field.GetText();
} }
blk->SetFields( dbFields );
DIALOG_DESIGN_BLOCK_PROPERTIES dlg( this, blk.get(), true ); DIALOG_DESIGN_BLOCK_PROPERTIES dlg( this, blk.get(), true );
if( dlg.ShowModal() != wxID_OK ) if( dlg.ShowModal() != wxID_OK )

View File

@ -39,11 +39,11 @@ extern wxString getElectricalTypeLabel( LABEL_FLAG_SHAPE aType );
SHEET_SYNCHRONIZATION_MODEL::SHEET_SYNCHRONIZATION_MODEL( SHEET_SYNCHRONIZATION_AGENT& aAgent, SHEET_SYNCHRONIZATION_MODEL::SHEET_SYNCHRONIZATION_MODEL( SHEET_SYNCHRONIZATION_AGENT& aAgent,
SCH_SHEET* aSheet, SCH_SHEET* aSheet,
SCH_SHEET_PATH& aPath ) : const SCH_SHEET_PATH& aPath ) :
m_selectedIndex( std::optional<unsigned>() ), m_selectedIndex( std::optional<unsigned>() ),
m_agent( aAgent ), m_agent( aAgent ),
m_sheet( aSheet ), m_sheet( aSheet ),
m_path( std::move( aPath ) ) m_path( aPath )
{ {
} }

View File

@ -71,7 +71,7 @@ public:
SHEET_SYNCHRONIZATION_MODEL( SHEET_SYNCHRONIZATION_AGENT& aAgent, SCH_SHEET* aSheet, SHEET_SYNCHRONIZATION_MODEL( SHEET_SYNCHRONIZATION_AGENT& aAgent, SCH_SHEET* aSheet,
SCH_SHEET_PATH& aPath ); const SCH_SHEET_PATH& aPath );
~SHEET_SYNCHRONIZATION_MODEL() override; ~SHEET_SYNCHRONIZATION_MODEL() override;
void GetValueByRow( wxVariant& variant, unsigned row, unsigned col ) const override; void GetValueByRow( wxVariant& variant, unsigned row, unsigned col ) const override;

View File

@ -31,13 +31,17 @@ class thread_pool;
class KICAD_SINGLETON class KICAD_SINGLETON
{ {
public: public:
KICAD_SINGLETON(){}; KICAD_SINGLETON() :
m_ThreadPool( nullptr ),
m_GLContextManager( nullptr )
{};
~KICAD_SINGLETON(); ~KICAD_SINGLETON();
void Init(); void Init();
public:
BS::thread_pool* m_ThreadPool; BS::thread_pool* m_ThreadPool;
GL_CONTEXT_MANAGER* m_GLContextManager; GL_CONTEXT_MANAGER* m_GLContextManager;
}; };