From bdee545841135344c8bc7cec0b74e10311ee7508 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Sat, 3 Jun 2023 07:28:03 -0400 Subject: [PATCH] Coverity warning fixes. --- common/tool/tool_manager.cpp | 3 +++ eeschema/net_navigator.cpp | 5 +++- .../cadstar/cadstar_sch_archive_plugin.h | 5 ++-- .../sch_plugins/ltspice/ltspice_schematic.cpp | 2 ++ eeschema/sim/simulator_frame.cpp | 4 +++- eeschema/symbol_lib_table.cpp | 10 +++++++- eeschema/symbol_viewer_frame.cpp | 23 +++++++++++-------- eeschema/widgets/search_handlers.cpp | 11 ++++++++- pcbnew/pcb_base_frame.cpp | 10 ++++---- pcbnew/pcb_shape.cpp | 2 +- pcbnew/teardrop/teardrop_utils.cpp | 4 ++++ pcbnew/tools/pcb_selection_tool.cpp | 6 ++--- qa/tests/pcbnew/test_pns_basics.cpp | 2 +- 13 files changed, 61 insertions(+), 26 deletions(-) diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 6bee705127..878e9845f1 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -1203,6 +1203,9 @@ void TOOL_MANAGER::setActiveState( TOOL_STATE* aState ) bool TOOL_MANAGER::IsToolActive( TOOL_ID aId ) const { auto it = m_toolIdIndex.find( aId ); + + wxCHECK( it != m_toolIdIndex.end(), false ); + return !it->second->idle; } diff --git a/eeschema/net_navigator.cpp b/eeschema/net_navigator.cpp index a24cd9c276..6db444e686 100644 --- a/eeschema/net_navigator.cpp +++ b/eeschema/net_navigator.cpp @@ -39,7 +39,10 @@ public: { } - NET_NAVIGATOR_ITEM_DATA() {} + NET_NAVIGATOR_ITEM_DATA() : + m_item( nullptr ) + { + } SCH_SHEET_PATH& GetSheetPath() { return m_sheetPath; } const SCH_ITEM* GetItem() const { return m_item; } diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h index 8edaa1cffa..cae6159645 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 Roberto Fernandez Bautista - * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -39,7 +39,8 @@ class SCH_SCREEN; class CADSTAR_SCH_ARCHIVE_PLUGIN : public SCH_PLUGIN { public: - CADSTAR_SCH_ARCHIVE_PLUGIN() + CADSTAR_SCH_ARCHIVE_PLUGIN() : + m_cacheTimestamp( 0 ) { m_reporter = &WXLOG_REPORTER::GetInstance(); m_progressReporter = nullptr; diff --git a/eeschema/sch_plugins/ltspice/ltspice_schematic.cpp b/eeschema/sch_plugins/ltspice/ltspice_schematic.cpp index b94ca43a8e..d71d584931 100644 --- a/eeschema/sch_plugins/ltspice/ltspice_schematic.cpp +++ b/eeschema/sch_plugins/ltspice/ltspice_schematic.cpp @@ -482,6 +482,8 @@ LTSPICE_SCHEMATIC::LT_SYMBOL LTSPICE_SCHEMATIC::SymbolBuilder( const wxString& a int lineNumber = 1; lt_symbol.Name = aAscFileName; + lt_symbol.SymbolType = LTSPICE_SCHEMATIC::SYMBOLTYPE::CELL; + lt_symbol.SymbolOrientation = LTSPICE_SCHEMATIC::ORIENTATION::R0; for( wxString line : wxSplit( aAsyFileContent, '\n' ) ) { diff --git a/eeschema/sim/simulator_frame.cpp b/eeschema/sim/simulator_frame.cpp index ff75d8371c..a5361c5e9c 100644 --- a/eeschema/sim/simulator_frame.cpp +++ b/eeschema/sim/simulator_frame.cpp @@ -531,7 +531,9 @@ SIMULATOR_FRAME::SIMULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) : NGSPICE_SIMULATOR_SETTINGS* settings = dynamic_cast( m_simulator->Settings().get() ); - if( settings->GetWorkbookFilename().IsEmpty() ) + wxCHECK2( settings, /* do nothing in release builds*/ ); + + if( settings && settings->GetWorkbookFilename().IsEmpty() ) settings->SetModelMode( NGSPICE_MODEL_MODE::LT_PSPICE ); m_simulator->Init(); diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index 7f44d398ee..7d7e4f3c6c 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -656,6 +656,8 @@ bool SYMBOL_LIB_TABLE::LoadGlobalTable( SYMBOL_LIB_TABLE& aTable ) SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); KICAD_SETTINGS* settings = mgr.GetAppSettings(); + wxCHECK( settings, false ); + wxString packagesPath = Pgm().GetLocalEnvVariables().at( wxT( "KICAD7_3RD_PARTY" ) ).GetValue(); if( settings->m_PcmLibAutoAdd ) @@ -688,7 +690,13 @@ bool SYMBOL_LIB_TABLE::LoadGlobalTable( SYMBOL_LIB_TABLE& aTable ) } for( const wxString& nickName : to_remove ) - aTable.RemoveRow( aTable.FindRow( nickName ) ); + { + SYMBOL_LIB_TABLE_ROW* row = aTable.FindRow( nickName ); + + wxCHECK2( row, continue ); + + aTable.RemoveRow( row ); + } } return tableExists; diff --git a/eeschema/symbol_viewer_frame.cpp b/eeschema/symbol_viewer_frame.cpp index 8deb82ddf5..d71d36ed86 100644 --- a/eeschema/symbol_viewer_frame.cpp +++ b/eeschema/symbol_viewer_frame.cpp @@ -685,6 +685,8 @@ bool SYMBOL_VIEWER_FRAME::ReCreateLibList() SYMBOL_LIB_TABLE_ROW* row = libTable->FindRow( aLib ); + wxCHECK( row, /* void */ ); + if( !row->GetIsVisible() ) return; @@ -1324,6 +1326,9 @@ void SYMBOL_VIEWER_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) { SYMBOL_LIB_TABLE* tbl = Prj().SchSymbolLibTable(); LIB_SYMBOL* symbol = GetSelectedSymbol(); + + wxCHECK2( tbl && symbol, break ); + const SYMBOL_LIB_TABLE_ROW* row = tbl->FindRow( symbol->GetLibId().GetLibNickname() ); if( !row ) @@ -1331,17 +1336,15 @@ void SYMBOL_VIEWER_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) wxString libfullname = row->GetFullURI( true ); - if( symbol ) - { - wxString lib( mail.GetPayload() ); - wxLogTrace( "KICAD_LIB_WATCH", "Received refresh symbol request for %s, current symbols is %s", lib, libfullname ); + wxString lib( mail.GetPayload() ); + wxLogTrace( "KICAD_LIB_WATCH", "Received refresh symbol request for %s, current symbols " + "is %s", lib, libfullname ); - if( lib == libfullname ) - { - wxLogTrace( "KICAD_LIB_WATCH", "Refreshing symbol %s", symbol->GetName() ); - updatePreviewSymbol(); - GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL); - } + if( lib == libfullname ) + { + wxLogTrace( "KICAD_LIB_WATCH", "Refreshing symbol %s", symbol->GetName() ); + updatePreviewSymbol(); + GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL ); } break; diff --git a/eeschema/widgets/search_handlers.cpp b/eeschema/widgets/search_handlers.cpp index d2a49505f8..8f9c67f3de 100644 --- a/eeschema/widgets/search_handlers.cpp +++ b/eeschema/widgets/search_handlers.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -211,6 +211,9 @@ int TEXT_SEARCH_HANDLER::Search( const wxString& aQuery ) if( item->Type() == SCH_TEXT_T ) { SCH_TEXT* text = dynamic_cast( item ); + + wxCHECK( text, false ); + if( text->Matches( frp, sheet ) ) { return true; @@ -219,6 +222,9 @@ int TEXT_SEARCH_HANDLER::Search( const wxString& aQuery ) else if( item->Type() == SCH_TEXTBOX_T ) { SCH_TEXTBOX* text = dynamic_cast( item ); + + wxCHECK( text, false ); + if( text->Matches( frp, sheet ) ) { return true; @@ -306,6 +312,9 @@ int LABEL_SEARCH_HANDLER::Search( const wxString& aQuery ) || item->Type() == SCH_HIER_LABEL_T ) { SCH_LABEL_BASE* lbl = dynamic_cast( item ); + + wxCHECK( lbl, false ); + if( lbl->Matches( frp, sheet ) ) { return true; diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 6fcc3354d7..f6dde9ff86 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -371,7 +371,7 @@ void PCB_BASE_FRAME::FocusOnItems( std::vector aItems, PCB_LAYER_ID { viewportPoly.BooleanSubtract( dialogPoly, SHAPE_POLY_SET::PM_FAST ); } - catch( const ClipperLib::clipperException& exc ) + catch( const std::exception& exc ) { // This may be overkill and could be an assertion but we are more likely to // find any clipper errors this way. @@ -422,7 +422,7 @@ void PCB_BASE_FRAME::FocusOnItems( std::vector aItems, PCB_LAYER_ID { itemPoly = static_cast( item )->GetBoundingHull(); } - catch( const ClipperLib::clipperException& exc ) + catch( const std::exception& exc ) { // This may be overkill and could be an assertion but we are more likely to // find any clipper errors this way. @@ -490,7 +490,7 @@ void PCB_BASE_FRAME::FocusOnItems( std::vector aItems, PCB_LAYER_ID { clippedPoly.BooleanIntersection( itemPoly, viewportPoly, SHAPE_POLY_SET::PM_FAST ); } - catch( const ClipperLib::clipperException& exc ) + catch( const std::exception& exc ) { // This may be overkill and could be an assertion but we are more likely to // find any clipper errors this way. @@ -517,7 +517,7 @@ void PCB_BASE_FRAME::FocusOnItems( std::vector aItems, PCB_LAYER_ID { itemPoly.Deflate( step, SHAPE_POLY_SET::ALLOW_ACUTE_CORNERS, ARC_LOW_DEF ); } - catch( const ClipperLib::clipperException& exc ) + catch( const std::exception& exc ) { // This may be overkill and could be an assertion but we are more likely to // find any clipper errors this way. @@ -1251,4 +1251,4 @@ void PCB_BASE_FRAME::OnFpChangeDebounceTimer( wxTimerEvent& aEvent ) DisplayError( this, ioe.What() ); } } -} \ No newline at end of file +} diff --git a/pcbnew/pcb_shape.cpp b/pcbnew/pcb_shape.cpp index 5d4a2ccc11..3b7026b8f8 100644 --- a/pcbnew/pcb_shape.cpp +++ b/pcbnew/pcb_shape.cpp @@ -340,7 +340,7 @@ std::shared_ptr PCB_SHAPE::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHI void PCB_SHAPE::swapData( BOARD_ITEM* aImage ) { PCB_SHAPE* image = dynamic_cast( aImage ); - assert( image ); + wxCHECK( image, /* void */ ); SwapShape( image ); diff --git a/pcbnew/teardrop/teardrop_utils.cpp b/pcbnew/teardrop/teardrop_utils.cpp index 40162a6f66..f1e11f0161 100644 --- a/pcbnew/teardrop/teardrop_utils.cpp +++ b/pcbnew/teardrop/teardrop_utils.cpp @@ -228,6 +228,10 @@ void TEARDROP_MANAGER::computeCurvedForRoundShape( const TEARDROP_PARAMETERS& aP Vpercent *= (double) aParams.m_TdMaxWidth / td_height; int radius = GetWidth( aOther ) / 2; + + // Don't divide by zero. No good can come of that. + wxCHECK2( radius != 0, radius = 1 ); + double minVpercent = double( aTrackHalfWidth ) / radius; double weaken = (Vpercent - minVpercent) / ( 1 - minVpercent ) / radius; diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index b3d1217a39..fd8341d24c 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -755,7 +755,7 @@ bool PCB_SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag, { GuessSelectionCandidates( collector, aWhere ); } - catch( const ClipperLib::clipperException& exc ) + catch( const std::exception& exc ) { wxLogWarning( wxS( "Exception \"%s\" occurred attemption to guess selection " "candidates." ), exc.what() ); @@ -2795,7 +2795,7 @@ int PCB_SELECTION_TOOL::hitTestDistance( const VECTOR2I& aWhere, BOARD_ITEM* aIt { footprint->GetBoundingHull().Collide( loc, aMaxDistance, &distance ); } - catch( const ClipperLib::clipperException& exc ) + catch( const std::exception& exc ) { // This may be overkill and could be an assertion but we are more likely to find // any clipper errors this way. @@ -2964,7 +2964,7 @@ void PCB_SELECTION_TOOL::GuessSelectionCandidates( GENERAL_COLLECTOR& aCollector { area = FOOTPRINT::GetCoverageArea( item, aCollector ); } - catch( const ClipperLib::clipperException& e ) + catch( const std::exception& e ) { wxLogError( wxT( "A clipper exception %s was detected." ), e.what() ); } diff --git a/qa/tests/pcbnew/test_pns_basics.cpp b/qa/tests/pcbnew/test_pns_basics.cpp index 010c1f3453..62c8609ff5 100644 --- a/qa/tests/pcbnew/test_pns_basics.cpp +++ b/qa/tests/pcbnew/test_pns_basics.cpp @@ -243,7 +243,7 @@ public: bool IsKeepout( const PNS::ITEM* aA, const PNS::ITEM* aB ) override { return false; } void AddMockRule( PNS::CONSTRAINT_TYPE aType, const PNS::ITEM* aItemA, const PNS::ITEM* aItemB, - PNS::CONSTRAINT aConstraint ) + PNS::CONSTRAINT& aConstraint ) { ITEM_KEY key;