From dd4298bb941fcf8af3669787287b0d6224de3e3a Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 11 Dec 2020 13:29:52 -0500 Subject: [PATCH] Coverity fixes: 280374, 313611, 313648, 313649, and 314720. --- eeschema/tools/ee_grid_helper.cpp | 1 + .../drc_test_provider_diff_pair_coupling.cpp | 36 +++++++++++-------- pcbnew/router/router_tool.cpp | 20 +++++++---- pcbnew/tools/edit_tool.cpp | 2 ++ utils/kicad2step/pcb/3d_resolver.cpp | 3 +- 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/eeschema/tools/ee_grid_helper.cpp b/eeschema/tools/ee_grid_helper.cpp index 09a9c70f5a..a4e986f4f0 100644 --- a/eeschema/tools/ee_grid_helper.cpp +++ b/eeschema/tools/ee_grid_helper.cpp @@ -53,6 +53,7 @@ EE_GRID_HELPER::EE_GRID_HELPER( TOOL_MANAGER* aToolMgr ) : { m_enableSnap = true; m_enableSnapLine = true; + m_enableGrid = true; m_snapItem = nullptr; KIGFX::VIEW* view = m_toolMgr->GetView(); diff --git a/pcbnew/drc/drc_test_provider_diff_pair_coupling.cpp b/pcbnew/drc/drc_test_provider_diff_pair_coupling.cpp index 4ac412c03d..f0053238fe 100644 --- a/pcbnew/drc/drc_test_provider_diff_pair_coupling.cpp +++ b/pcbnew/drc/drc_test_provider_diff_pair_coupling.cpp @@ -43,8 +43,8 @@ - DRCE_TOO_MANY_VIAS Todo: - arc support. - - improve recognition of coupled segments (now anything that's parallel is considered coupled, causing - DRC errors on meanders) + - improve recognition of coupled segments (now anything that's parallel is considered + coupled, causing DRC errors on meanders) */ namespace test { @@ -169,7 +169,10 @@ struct DIFF_PAIR_COUPLED_SEGMENTS DIFF_PAIR_COUPLED_SEGMENTS() : parentN( nullptr ), - parentP( nullptr ) + parentP( nullptr ), + computedGap( 0 ), + layer( UNDEFINED_LAYER ), + couplingOK( false ) {} }; @@ -349,7 +352,8 @@ bool test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run() wxString nameP = niP->GetNetname(); wxString nameN = niN->GetNetname(); - reportAux( wxString::Format( "Rule '%s', DP: (+) %s - (-) %s", it.first.parentRule->m_Name, nameP, nameN ) ); + reportAux( wxString::Format( "Rule '%s', DP: (+) %s - (-) %s", + it.first.parentRule->m_Name, nameP, nameN ) ); extractDiffPairCoupledItems( it.second, copperTree ); @@ -359,8 +363,10 @@ bool test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run() drc_dbg(10, " coupled prims : %d\n", (int) it.second.coupled.size() ); - OPT gapConstraint = it.first.parentRule->FindConstraint( DIFF_PAIR_GAP_CONSTRAINT ); - OPT maxUncoupledConstraint = it.first.parentRule->FindConstraint( DIFF_PAIR_MAX_UNCOUPLED_CONSTRAINT ); + OPT gapConstraint = + it.first.parentRule->FindConstraint( DIFF_PAIR_GAP_CONSTRAINT ); + OPT maxUncoupledConstraint = + it.first.parentRule->FindConstraint( DIFF_PAIR_MAX_UNCOUPLED_CONSTRAINT ); for( auto& item : it.second.itemsN ) { @@ -401,7 +407,8 @@ bool test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run() overlay->Line( cpair.coupledN ); } - drc_dbg(10, " len %d gap %d l %d\n", length, gap, cpair.parentP->GetLayer() ); + drc_dbg( 10, " len %d gap %d l %d\n", length, gap, + cpair.parentP->GetLayer() ); if( gapConstraint ) { @@ -412,7 +419,6 @@ bool test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run() if ( val.HasMax() && gap > val.Max() ) insideRange = false; - // if(val.HasMin() && val.HasMax() ) // drc_dbg(10, "Vmin %d vmax %d\n", val.Min(), val.Max() ); @@ -424,10 +430,10 @@ bool test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run() } int totalLen = std::max( it.second.totalLengthN, it.second.totalLengthP ); - reportAux( wxString::Format( " - coupled length: %s, total length: %s", + reportAux( wxString::Format( " - coupled length: %s, total length: %s", - MessageTextFromValue( userUnits(), it.second.totalCoupled ), - MessageTextFromValue( userUnits(), totalLen ) ) ); + MessageTextFromValue( userUnits(), it.second.totalCoupled ), + MessageTextFromValue( userUnits(), totalLen ) ) ); int totalUncoupled = totalLen - it.second.totalCoupled; @@ -471,16 +477,16 @@ bool test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run() auto val = gapConstraint->GetValue(); auto drcItem = DRC_ITEM::Create( DRCE_DIFF_PAIR_GAP_OUT_OF_RANGE ); - m_msg = drcItem->GetErrorText() + " (" + gapConstraint->GetParentRule()->m_Name + " "; + m_msg = drcItem->GetErrorText() + " (" + + gapConstraint->GetParentRule()->m_Name + " "; if( val.HasMin() ) m_msg += wxString::Format( _( "minimum gap: %s; " ), - MessageTextFromValue( userUnits(), val.Min() ) ); + MessageTextFromValue( userUnits(), val.Min() ) ); if( val.HasMax() ) m_msg += wxString::Format( _( "maximum gap: %s; " ), - MessageTextFromValue( userUnits(), val.Max() ) ); - + MessageTextFromValue( userUnits(), val.Max() ) ); m_msg += wxString::Format( _( "actual: %s)" ), MessageTextFromValue( userUnits(), cpair.computedGap ) ); diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 0ba906d5c2..96ee34b056 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -116,7 +116,8 @@ static const TOOL_ACTION ACT_PlaceMicroVia( "pcbnew.InteractiveRouter.PlaceMicro _( "Place Microvia" ), _( "Adds a microvia at the end of currently routed track." ), via_microvia_xpm, AF_NONE, (void*) VIA_ACTION_FLAGS::MICROVIA ); -static const TOOL_ACTION ACT_SelLayerAndPlaceThroughVia( "pcbnew.InteractiveRouter.SelLayerAndPlaceVia", +static const TOOL_ACTION ACT_SelLayerAndPlaceThroughVia( + "pcbnew.InteractiveRouter.SelLayerAndPlaceVia", AS_CONTEXT, '<', LEGACY_HK_NAME( "Select Layer and Add Through Via" ), _( "Select Layer and Place Through Via..." ), @@ -124,7 +125,8 @@ static const TOOL_ACTION ACT_SelLayerAndPlaceThroughVia( "pcbnew.InteractiveRout select_w_layer_xpm, AF_NONE, (void*) ( VIA_ACTION_FLAGS::VIA | VIA_ACTION_FLAGS::SELECT_LAYER ) ); -static const TOOL_ACTION ACT_SelLayerAndPlaceBlindVia( "pcbnew.InteractiveRouter.SelLayerAndPlaceBlindVia", +static const TOOL_ACTION ACT_SelLayerAndPlaceBlindVia( + "pcbnew.InteractiveRouter.SelLayerAndPlaceBlindVia", AS_CONTEXT, MD_ALT + '<', LEGACY_HK_NAME( "Select Layer and Add Blind/Buried Via" ), _( "Select Layer and Place Blind/Buried Via..." ), @@ -488,6 +490,7 @@ void ROUTER_TOOL::handleCommonEvents( const TOOL_EVENT& aEvent ) case '0': { auto logger = m_router->Logger(); + if( ! logger ) return; @@ -502,17 +505,18 @@ void ROUTER_TOOL::handleCommonEvents( const TOOL_EVENT& aEvent ) if( evt.item && evt.item->Parent() ) id = evt.item->Parent()->m_Uuid.AsString(); - fprintf(f, "event %d %d %d %s\n", evt.p.x, evt.p.y, evt.type, (const char*) id.c_str() ); + fprintf( f, "event %d %d %d %s\n", evt.p.x, evt.p.y, evt.type, + (const char*) id.c_str() ); } - fclose(f); + fclose( f ); // Export as *.kicad_pcb format, using a strategy which is specifically chosen // as an example on how it could also be used to send it to the system clipboard. PCB_IO pcb_io; - pcb_io.Save("/tmp/pns.dump", m_iface->GetBoard(), nullptr ); + pcb_io.Save( "/tmp/pns.dump", m_iface->GetBoard(), nullptr ); break; } @@ -662,6 +666,8 @@ int ROUTER_TOOL::onViaCommand( const TOOL_EVENT& aEvent ) int ROUTER_TOOL::handleLayerSwitch( const TOOL_EVENT& aEvent, bool aForceVia ) { + wxCHECK( m_router, 0 ); + if( !IsToolActive() ) return 0; @@ -747,7 +753,7 @@ int ROUTER_TOOL::handleLayerSwitch( const TOOL_EVENT& aEvent, bool aForceVia ) targetLayer = frame()->SelectLayer( static_cast( currentLayer ), LSET::AllNonCuMask(), dlgPosition ); - // Reset the cursor to the position where the event occured + // Reset the cursor to the position where the event occurred controls()->SetCursorPosition( aEvent.HasPosition() ? aEvent.Position() : dlgPosition ); } } @@ -1010,7 +1016,7 @@ void ROUTER_TOOL::performRouting() { setCursor(); - // Don't crash if we missed an operation that cancelled routing. + // Don't crash if we missed an operation that canceled routing. if( !m_router->RoutingInProgress() ) { if( evt->IsCancelInteractive() ) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index dafca15697..b37cdedae8 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -692,6 +692,8 @@ int EDIT_TOOL::ChangeTrackWidth( const TOOL_EVENT& aEvent ) { TRACK* track = dynamic_cast( item ); + wxCHECK( track, 0 ); + m_commit->Modify( track ); int new_width = board()->GetDesignSettings().GetCurrentTrackWidth(); diff --git a/utils/kicad2step/pcb/3d_resolver.cpp b/utils/kicad2step/pcb/3d_resolver.cpp index 4f07685f79..c515d217b8 100644 --- a/utils/kicad2step/pcb/3d_resolver.cpp +++ b/utils/kicad2step/pcb/3d_resolver.cpp @@ -2,6 +2,7 @@ * This program source code file is part kicad2mcad * * Copyright (C) 2015-2016 Cirilo Bernardo + * Copyright (C) 2020 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 @@ -1069,7 +1070,7 @@ static bool getHollerith( const std::string& aString, size_t& aIndex, wxString& i2 += nchars; } - if( aString[i2] != '"' ) + if( i2 >= aString.size() || aString[i2] != '"' ) { std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";