Coverity fixes and code cleaning.

(cherry picked from commit 789bf6455a)
This commit is contained in:
Wayne Stambaugh 2023-03-02 09:04:37 -05:00
parent a9447aa8c7
commit 2c7f44f78d
17 changed files with 113 additions and 59 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 Jon Evans <jon@craftyjon.com>
* 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
@ -178,7 +178,15 @@ bool DATABASE_CONNECTION::Disconnect()
return false;
}
m_conn->disconnect();
try
{
m_conn->disconnect();
}
catch( boost::locale::conv::conversion_error& exc )
{
wxLogTrace( traceDatabase, wxT( "Disconnect() error \"%s\" occured." ), exc.what() );
return false;
}
return !m_conn->connected();
}

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2004-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2004-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
@ -78,12 +78,16 @@ BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, KIWAY_PLAYER )
EVT_ACTIVATE( EDA_DRAW_FRAME::onActivate )
END_EVENT_TABLE()
bool EDA_DRAW_FRAME::m_openGLFailureOccured = false;
EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
long aStyle, const wxString& aFrameName, const EDA_IU_SCALE& aIuScale ) :
KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName, aIuScale )
long aStyle, const wxString& aFrameName,
const EDA_IU_SCALE& aIuScale ) :
KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName, aIuScale ),
m_socketServer( nullptr )
{
m_socketServer = nullptr;
m_mainToolBar = nullptr;
@ -171,8 +175,8 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
OnMove( dummy );
// we need to kludge the msg panel to the correct size again
// especially important even for first launches as the constructor of the window here usually doesn't
// have the correct dpi awareness yet
// especially important even for first launches as the constructor of the window
// here usually doesn't have the correct dpi awareness yet
m_frameSize.y += m_msgFrameHeight;
m_msgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight( this );
m_frameSize.y -= m_msgFrameHeight;
@ -609,7 +613,8 @@ void EDA_DRAW_FRAME::DisplayGridMsg()
{
wxString msg;
msg.Printf( wxS( "grid %s" ), MessageTextFromValue( GetCanvas()->GetGAL()->GetGridSize().x, false ) );
msg.Printf( wxS( "grid %s" ), MessageTextFromValue( GetCanvas()->GetGAL()->GetGridSize().x,
false ) );
SetStatusText( msg, 4 );
}

View File

@ -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
@ -42,6 +42,8 @@ void SEARCH_PANE::OnLanguageChange()
wxWindow* page = m_notebook->GetPage( i );
SEARCH_PANE_TAB* tab = dynamic_cast<SEARCH_PANE_TAB*>( page );
wxCHECK( tab, /* void */ );
tab->RefreshColumnNames();
m_notebook->SetPageText( i, wxGetTranslation( tab->GetSearchHandler()->GetName() ) );
}
@ -103,4 +105,4 @@ void SEARCH_PANE::OnNotebookPageChanged( wxBookCtrlEvent& aEvent )
SEARCH_PANE_TAB* SEARCH_PANE::GetCurrentTab() const
{
return dynamic_cast<SEARCH_PANE_TAB*>( m_notebook->GetCurrentPage() );
}
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2001 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004-2022 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2004-2023 KiCad Developers, see change_log.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
@ -122,10 +122,14 @@ DIALOG_LIB_TEXT_PROPERTIES::~DIALOG_LIB_TEXT_PROPERTIES()
bool DIALOG_LIB_TEXT_PROPERTIES::TransferDataToWindow()
{
LIB_SYMBOL* symbol = m_graphicText->GetParent();
LIB_SYMBOL* symbol = nullptr;
if( m_graphicText )
{
symbol = m_graphicText->GetParent();
wxCHECK( symbol, false );
m_textSize.SetValue( m_graphicText->GetTextWidth() );
m_StyledTextCtrl->SetValue( m_graphicText->GetText() );
m_StyledTextCtrl->EmptyUndoBuffer();

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2004-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
@ -189,7 +189,8 @@ wxString SCH_FIELD::GetShownText( int aDepth, bool aAllowExtraText ) const
std::function<bool( wxString* )> labelResolver =
[&]( wxString* token ) -> bool
{
return static_cast<SCH_LABEL_BASE*>( m_parent )->ResolveTextVar( token, aDepth + 1 );
return static_cast<SCH_LABEL_BASE*>( m_parent )->ResolveTextVar( token,
aDepth + 1 );
};
wxString text = EDA_TEXT::GetShownText();
@ -1040,6 +1041,8 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground ) const
std::vector<wxString> pageHrefs;
BOX2I bbox = GetBoundingBox();
wxCHECK( label, /* void */ );
label->GetIntersheetRefs( &pages );
for( const std::pair<wxString, wxString>& page : pages )

View File

@ -76,12 +76,14 @@ BOARD* BOARD_COMMIT::GetBoard() const
COMMIT& BOARD_COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType )
{
wxCHECK( aItem, *this );
aItem->ClearFlags( IS_MODIFIED_CHILD );
// If aItem belongs a footprint, the full footprint will be saved because undo/redo does
// not handle "sub items" modifications. This has implications for auto-zone-refill, so
// we need to store a bit more information.
if( aItem && aChangeType == CHT_MODIFY )
if( aChangeType == CHT_MODIFY )
{
if( aItem->Type() == PCB_FOOTPRINT_T )
{

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-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
@ -43,22 +43,9 @@
#include <dialog_graphic_item_properties_base.h>
#include <tools/drawing_tool.h>
class DIALOG_GRAPHIC_ITEM_PROPERTIES : public DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE
{
private:
PCB_BASE_EDIT_FRAME* m_parent;
PCB_SHAPE* m_item;
FP_SHAPE* m_fp_item;
UNIT_BINDER m_startX, m_startY;
UNIT_BINDER m_endX, m_endY;
UNIT_BINDER m_angle;
UNIT_BINDER m_thickness;
UNIT_BINDER m_bezierCtrl1X, m_bezierCtrl1Y;
UNIT_BINDER m_bezierCtrl2X, m_bezierCtrl2Y;
bool m_flipStartEnd;
public:
DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BOARD_ITEM* aItem );
~DIALOG_GRAPHIC_ITEM_PROPERTIES() {};
@ -79,6 +66,20 @@ private:
void onFilledCheckbox( wxCommandEvent& event ) override;
bool Validate() override;
private:
PCB_BASE_EDIT_FRAME* m_parent;
PCB_SHAPE* m_item;
FP_SHAPE* m_fp_item;
UNIT_BINDER m_startX, m_startY;
UNIT_BINDER m_endX, m_endY;
UNIT_BINDER m_angle;
UNIT_BINDER m_thickness;
UNIT_BINDER m_bezierCtrl1X, m_bezierCtrl1Y;
UNIT_BINDER m_bezierCtrl2X, m_bezierCtrl2Y;
bool m_flipStartEnd;
};
DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent,
@ -441,7 +442,7 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::Validate()
double max_offset = std::max( std::abs( center.x ) + radius,
std::abs( center.y ) + radius );
if( max_offset >= ( std::numeric_limits<VECTOR2I::coord_type>::max() / 2 )
if( max_offset >= ( std::numeric_limits<VECTOR2I::coord_type>::max() / 2.0 )
|| center == start || center == end )
{
errors.Add( wxString::Format( _( "Invalid Arc with radius %f and angle %f." ),

View File

@ -392,6 +392,8 @@ bool test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run()
int length = dp.coupledN.Length();
int gap = dp.coupledN.Distance( dp.coupledP );
wxCHECK2( dp.parentN && dp.parentP, continue );
gap -= dp.parentN->GetWidth() / 2;
gap -= dp.parentP->GetWidth() / 2;

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-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
@ -33,12 +33,11 @@
// Constructor and destructor
NETINFO_LIST::NETINFO_LIST( BOARD* aParent ) :
m_parent( aParent )
m_parent( aParent ),
m_newNetCode( 0 )
{
// Make sure that the unconnected net has number 0
AppendNet( new NETINFO_ITEM( aParent, wxEmptyString, 0 ) );
m_newNetCode = 0;
}
@ -51,6 +50,7 @@ NETINFO_LIST::~NETINFO_LIST()
void NETINFO_LIST::clear()
{
NETNAMES_MAP::iterator it, itEnd;
for( it = m_netNames.begin(), itEnd = m_netNames.end(); it != itEnd; ++it )
delete it->second;

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
* Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
* Copyright (C) 2012-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2012-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
@ -315,7 +315,6 @@ void PCB_FOOTPRINT::DoLayerContentsObjects( XNODE* aNode, PCB_FOOTPRINT* aFootpr
if( m_callbacks->GetLayerType( PCadLayer ) == LAYER_TYPE_PLANE )
{
plane_layer_polygon = new VERTICES_ARRAY;
wxASSERT( plane_layer );
plane_layer->FormPolygon( lNode, plane_layer_polygon, aDefaultMeasurementUnit,
aActualConversion );
plane_layer->m_cutouts.Add( plane_layer_polygon );

View File

@ -2,7 +2,7 @@
* KiRouter - a push-and-(sometimes-)shove PCB router
*
* Copyright (C) 2013-2014 CERN
* Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software: you can redistribute it and/or modify it
@ -61,13 +61,14 @@ void LOGGER::Save( const std::string& aFilename )
}
void LOGGER::Log( LOGGER::EVENT_TYPE evt, const VECTOR2I& pos, const ITEM* item, const SIZES_SETTINGS* sizes )
void LOGGER::Log( LOGGER::EVENT_TYPE evt, const VECTOR2I& pos, const ITEM* item,
const SIZES_SETTINGS* sizes )
{
LOGGER::EVENT_ENTRY ent;
ent.type = evt;
ent.p = pos;
ent.uuid = KIID(0);
ent.uuid = KIID( 0 );
if( sizes )
{

View File

@ -2,7 +2,7 @@
* KiRouter - a push-and-(sometimes-)shove PCB router
*
* Copyright (C) 2013-2014 CERN
* Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software: you can redistribute it and/or modify it
@ -65,7 +65,8 @@ public:
void Save( const std::string& aFilename );
void Clear();
void Log( EVENT_TYPE evt, const VECTOR2I& pos = VECTOR2I(), const ITEM* item = nullptr, const SIZES_SETTINGS* sizes = nullptr );
void Log( EVENT_TYPE evt, const VECTOR2I& pos = VECTOR2I(), const ITEM* item = nullptr,
const SIZES_SETTINGS* sizes = nullptr );
const std::vector<EVENT_ENTRY>& GetEvents()
{

View File

@ -2,7 +2,7 @@
* KiRouter - a push-and-(sometimes-)shove PCB router
*
* Copyright (C) 2013-2019 CERN
* Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
@ -275,7 +275,8 @@ int NODE::QueryColliding( const ITEM* aItem, NODE::OBSTACLES& aObstacles, int aK
if( aItem->IsVirtual() )
return 0;
DEFAULT_OBSTACLE_VISITOR visitor( aObstacles, aItem, aKindMask, aDifferentNetsOnly, aOverrideClearance );
DEFAULT_OBSTACLE_VISITOR visitor( aObstacles, aItem, aKindMask, aDifferentNetsOnly,
aOverrideClearance );
#ifdef DEBUG
assert( allocNodes.find( this ) != allocNodes.end() );
@ -324,6 +325,7 @@ NODE::OPT_OBSTACLE NODE::NearestObstacle( const LINE* aLine, int aKindMask,
OBSTACLE nearest;
nearest.m_item = nullptr;
nearest.m_distFirst = INT_MAX;
nearest.m_maxFanoutWidth = 0;
auto updateNearest =
[&]( const SHAPE_LINE_CHAIN::INTERSECTION& pt, ITEM* obstacle,
@ -348,7 +350,6 @@ NODE::OPT_OBSTACLE NODE::NearestObstacle( const LINE* aLine, int aKindMask,
std::vector<SHAPE_LINE_CHAIN::INTERSECTION> intersectingPts;
int layer = aLine->Layer();
for( const OBSTACLE& obstacle : obstacleList )
{
if( aRestrictedSet && aRestrictedSet->find( obstacle.m_item ) == aRestrictedSet->end() )
@ -720,9 +721,10 @@ void NODE::Add( std::unique_ptr< ITEM > aItem, bool aAllowRedundant )
case ITEM::LINE_T:
{
//fixme(twl): I don't like unique_ptr in this methods as the router has its own garbage collecting
//mechanism. This particular case is used exclusively in ROUTER::GetUpdatedItems() for
//dumping debug logs. Please don't call Add ( up<LINE> ) otherwise, dragons live here.
// fixme(twl): I don't like unique_ptr in this methods as the router has its own garbage
// collecting mechanism. This particular case is used exclusively in
// ROUTER::GetUpdatedItems() for dumping debug logs. Please don't call Add ( up<LINE> )
// otherwise, dragons live here.
LINE *l = static_cast<LINE*>( aItem.get() );
Add( *l );
break;
@ -1072,7 +1074,7 @@ const LINE NODE::AssembleLine( LINKED_ITEM* aSeg, int* aOriginSegmentIndex,
// Remove duplicate verts, but do NOT remove colinear segments here!
pl.Line().Simplify( false );
// TODO: maintain actual segment index under simplifcation system
// TODO: maintain actual segment index under simplification system
if( aOriginSegmentIndex && *aOriginSegmentIndex >= pl.SegmentCount() )
*aOriginSegmentIndex = pl.SegmentCount() - 1;
@ -1275,8 +1277,7 @@ JOINT& NODE::touchJoint( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int a
break;
}
}
}
while( merged );
} while( merged );
return m_joints.insert( TagJointPair( tag, jt ) )->second;
}

View File

@ -2,7 +2,7 @@
* KiRouter - a push-and-(sometimes-)shove PCB router
*
* Copyright (C) 2013-2014 CERN
* Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software: you can redistribute it and/or modify it
@ -142,7 +142,9 @@ const ITEM_SET ROUTER::QueryHoverItems( const VECTOR2I& aP, bool aUseClearance )
}
}
else
{
return m_placer->CurrentNode()->HitTest( aP );
}
}
@ -776,7 +778,7 @@ bool ROUTER::movePlacing( const VECTOR2I& aP, ITEM* aEndItem )
void ROUTER::GetUpdatedItems( std::vector<PNS::ITEM*>& aRemoved, std::vector<PNS::ITEM*>& aAdded,
std::vector<PNS::ITEM*>& aHeads )
{
NODE *node;
NODE *node = nullptr;
ITEM_SET current;
if( m_state == ROUTE_TRACK )
@ -790,6 +792,11 @@ void ROUTER::GetUpdatedItems( std::vector<PNS::ITEM*>& aRemoved, std::vector<PNS
current = m_dragger->Traces();
}
// There probably should be a debugging assertion and possibly a PNS_LOGGER call here but
// I'm not sure how to be proceed WLS.
if( !node )
return;
node->GetUpdatedItems( aRemoved, aAdded );
for( auto item : current.CItems() )

View File

@ -2,7 +2,7 @@
* KiRouter - a push-and-(sometimes-)shove PCB router
*
* Copyright (C) 2014 CERN
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016, 2023 KiCad Developers, see AUTHORS.txt for contributors.
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software: you can redistribute it and/or modify it
@ -49,7 +49,8 @@ public:
m_diffPairGap( 180000 ),
m_diffPairViaGap( 180000 ),
m_diffPairViaGapSameAsTraceGap( true ),
m_holeToHole( 0 )
m_holeToHole( 0 ),
m_diffPairHoleToHole( 0 )
{};
~SIZES_SETTINGS() {};
@ -84,7 +85,11 @@ public:
void SetDiffPairWidth( int aWidth ) { m_diffPairWidth = aWidth; }
void SetDiffPairGap( int aGap ) { m_diffPairGap = aGap; }
void SetDiffPairViaGapSameAsTraceGap ( bool aEnable ) { m_diffPairViaGapSameAsTraceGap = aEnable; }
void SetDiffPairViaGapSameAsTraceGap ( bool aEnable )
{
m_diffPairViaGapSameAsTraceGap = aEnable;
}
void SetDiffPairViaGap( int aGap ) { m_diffPairViaGap = aGap; }
int ViaDiameter() const { return m_viaDiameter; }

View File

@ -2,7 +2,7 @@
* KiRouter - a push-and-(sometimes-)shove PCB router
*
* Copyright (C) 2013-2014 CERN
* Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software: you can redistribute it and/or modify it
@ -195,6 +195,8 @@ const BOX2I ROUTER_PREVIEW_ITEM::ViewBBox() const
void ROUTER_PREVIEW_ITEM::drawLineChain( const SHAPE_LINE_CHAIN_BASE* aL, KIGFX::GAL* gal ) const
{
wxCHECK( aL, /* void */ );
gal->SetIsFill( false );
for( int s = 0; s < aL->GetSegmentCount(); s++ )
@ -211,7 +213,7 @@ void ROUTER_PREVIEW_ITEM::drawLineChain( const SHAPE_LINE_CHAIN_BASE* aL, KIGFX:
gal->DrawArc( arc.GetCenter(), arc.GetRadius(), start_angle, start_angle + angle);
}
if( aL && aL->IsClosed() )
if( aL->IsClosed() )
gal->DrawLine( aL->GetSegment( -1 ).B, aL->GetSegment( 0 ).A );
}

View File

@ -756,7 +756,18 @@ bool PCB_SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag,
// Apply some ugly heuristics to avoid disambiguation menus whenever possible
if( collector.GetCount() > 1 && !m_skip_heuristics )
GuessSelectionCandidates( collector, aWhere );
{
try
{
GuessSelectionCandidates( collector, aWhere );
}
catch( const ClipperLib::clipperException& exc )
{
wxLogWarning( wxS( "Exception \"%s\" occurred attemption to guess selection "
"candidates." ), exc.what() );
return false;
}
}
// If still more than one item we're going to have to ask the user.
if( collector.GetCount() > 1 )