Coverity fixes

CIDs:
- 153097
- 157120
- 157119
- 155148
- 155146
- 153103
- 153099
- 153095
- 153087
- 153086
This commit is contained in:
Maciej Suminski 2017-03-11 22:18:45 +01:00
parent 082b8dd2a9
commit fe4f02f5b9
10 changed files with 54 additions and 47 deletions

View File

@ -87,9 +87,9 @@ COLOR_SWATCH::COLOR_SWATCH( wxWindow* aParent, COLOR4D aColor, int aID,
SetSizer( sizer ); SetSizer( sizer );
auto swatch = makeColorSwatch( this, m_color, aID ); auto swatch = makeColorSwatch( this, m_color, aID );
m_swatch = swatch.get(); // hold a handle m_swatch = swatch.release(); // hold a handle
sizer->Add( swatch.release(), 0, 0 ); sizer->Add( m_swatch, 0, 0 );
// forward click to any other listeners, since we don't want them // forward click to any other listeners, since we don't want them
m_swatch->Bind( wxEVT_LEFT_DOWN, &COLOR_SWATCH::rePostEvent, this ); m_swatch->Bind( wxEVT_LEFT_DOWN, &COLOR_SWATCH::rePostEvent, this );

View File

@ -44,11 +44,12 @@ public:
virtual const BOX2I ViewBBox() const override virtual const BOX2I ViewBBox() const override
{ {
BOX2I bb; bb.SetMaximum();
return bb;
if( !m_item ) if( !m_item )
return BOX2I(); {
BOX2I bb;
bb.SetMaximum();
return bb;
}
return m_item->ViewBBox(); return m_item->ViewBBox();
} }

View File

@ -957,12 +957,6 @@ bool DIALOG_PAD_PROPERTIES::TransferDataFromWindow()
commit.Modify( m_currentPad ); commit.Modify( m_currentPad );
wxSize size;
MODULE* footprint = m_currentPad->GetParent();
if( footprint )
footprint->SetLastEditTime();
// redraw the area where the pad was, without pad (delete pad on screen) // redraw the area where the pad was, without pad (delete pad on screen)
m_currentPad->SetFlags( DO_NOT_DRAW ); m_currentPad->SetFlags( DO_NOT_DRAW );
m_parent->GetCanvas()->RefreshDrawingRect( m_currentPad->GetBoundingBox() ); m_parent->GetCanvas()->RefreshDrawingRect( m_currentPad->GetBoundingBox() );
@ -978,16 +972,21 @@ bool DIALOG_PAD_PROPERTIES::TransferDataFromWindow()
rastnestIsChanged = true; rastnestIsChanged = true;
} }
// compute the pos 0 value, i.e. pad position for footprint with orientation = 0 wxSize size;
// i.e. relative to footprint origin (footprint position) MODULE* footprint = m_currentPad->GetParent();
wxPoint pt = m_currentPad->GetPosition() - footprint->GetPosition();
RotatePoint( &pt, -footprint->GetOrientation() ); if( footprint )
{
footprint->SetLastEditTime();
m_currentPad->SetPos0( pt ); // compute the pos 0 value, i.e. pad position for footprint with orientation = 0
// i.e. relative to footprint origin (footprint position)
m_currentPad->SetOrientation( m_padMaster->GetOrientation() * isign wxPoint pt = m_currentPad->GetPosition() - footprint->GetPosition();
+ footprint->GetOrientation() ); RotatePoint( &pt, -footprint->GetOrientation() );
m_currentPad->SetPos0( pt );
m_currentPad->SetOrientation( m_padMaster->GetOrientation() * isign
+ footprint->GetOrientation() );
}
m_currentPad->SetSize( m_padMaster->GetSize() ); m_currentPad->SetSize( m_padMaster->GetSize() );

View File

@ -177,7 +177,7 @@ XNODE* PCB_MODULE::FindPatternMultilayerSection( XNODE* aNode, wxString* aPatGra
if( FindNode( aNode, wxT( "patternGraphicsDef" ) ) ) if( FindNode( aNode, wxT( "patternGraphicsDef" ) ) )
lNode = FindNode( aNode, wxT( "patternGraphicsDef" ) ); lNode = FindNode( aNode, wxT( "patternGraphicsDef" ) );
else else if( pNode )
lNode = FindNode( pNode, wxT( "patternGraphicsDef" ) ); lNode = FindNode( pNode, wxT( "patternGraphicsDef" ) );
if( *aPatGraphRefName == wxEmptyString ) // no patern delection, the first is actual... if( *aPatGraphRefName == wxEmptyString ) // no patern delection, the first is actual...

View File

@ -40,7 +40,7 @@ class ALGO_BASE
{ {
public: public:
ALGO_BASE( ROUTER* aRouter ) : ALGO_BASE( ROUTER* aRouter ) :
m_router( aRouter ) m_debugDecorator( nullptr ), m_router( aRouter )
{} {}
virtual ~ALGO_BASE() {} virtual ~ALGO_BASE() {}

View File

@ -195,7 +195,11 @@ INDEX::ITEM_SHAPE_INDEX* INDEX::getSubindex( const ITEM* aItem )
break; break;
} }
assert( idx_n >= 0 && idx_n < MaxSubIndices ); if( idx_n < 0 || idx_n >= MaxSubIndices )
{
assert( false );
return nullptr;
}
if( !m_subIndices[idx_n] ) if( !m_subIndices[idx_n] )
m_subIndices[idx_n] = new ITEM_SHAPE_INDEX; m_subIndices[idx_n] = new ITEM_SHAPE_INDEX;
@ -207,6 +211,9 @@ void INDEX::Add( ITEM* aItem )
{ {
ITEM_SHAPE_INDEX* idx = getSubindex( aItem ); ITEM_SHAPE_INDEX* idx = getSubindex( aItem );
if( !idx )
return;
idx->Add( aItem ); idx->Add( aItem );
m_allItems.insert( aItem ); m_allItems.insert( aItem );
int net = aItem->Net(); int net = aItem->Net();
@ -221,9 +228,11 @@ void INDEX::Remove( ITEM* aItem )
{ {
ITEM_SHAPE_INDEX* idx = getSubindex( aItem ); ITEM_SHAPE_INDEX* idx = getSubindex( aItem );
if( !idx )
return;
idx->Remove( aItem ); idx->Remove( aItem );
m_allItems.erase( aItem ); m_allItems.erase( aItem );
int net = aItem->Net(); int net = aItem->Net();
if( net >= 0 && m_netMap.find( net ) != m_netMap.end() ) if( net >= 0 && m_netMap.find( net ) != m_netMap.end() )

View File

@ -153,6 +153,7 @@ PNS_PCBNEW_RULE_RESOLVER::PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard, PNS::ROUTER*
m_overrideNetA = 0; m_overrideNetA = 0;
m_overrideNetB = 0; m_overrideNetB = 0;
m_overrideClearance = 0; m_overrideClearance = 0;
m_useDpGap = false;
} }

View File

@ -812,29 +812,22 @@ int PCB_EDITOR_CONTROL::ZoneMerge( const TOOL_EVENT& aEvent )
netcode = curr_area->GetNetCode(); netcode = curr_area->GetNetCode();
if( firstZone ) if( firstZone->GetNetCode() != netcode )
{ continue;
if( firstZone->GetNetCode() != netcode )
continue;
if( curr_area->GetPriority() != firstZone->GetPriority() ) if( curr_area->GetPriority() != firstZone->GetPriority() )
continue; continue;
if( curr_area->GetIsKeepout() != firstZone->GetIsKeepout() ) if( curr_area->GetIsKeepout() != firstZone->GetIsKeepout() )
continue; continue;
if( curr_area->GetLayer() != firstZone->GetLayer() ) if( curr_area->GetLayer() != firstZone->GetLayer() )
continue; continue;
if( !board->TestAreaIntersection( curr_area, firstZone ) ) if( !board->TestAreaIntersection( curr_area, firstZone ) )
continue; continue;
toMerge.push_back( curr_area ); toMerge.push_back( curr_area );
}
else
{
toMerge.push_back( curr_area );
}
} }
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );

View File

@ -785,12 +785,13 @@ int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent )
wxString fileName; wxString fileName;
PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame ); PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
BOARD* board = getModel<BOARD>();
BOARD_COMMIT commit( editFrame );
if( !editFrame ) if( !editFrame )
return 0; return 0;
BOARD* board = getModel<BOARD>();
BOARD_COMMIT commit( editFrame );
// Pick a file to append // Pick a file to append
if( !AskLoadBoardFileName( editFrame, &open_ctl, &fileName, true ) ) if( !AskLoadBoardFileName( editFrame, &open_ctl, &fileName, true ) )
return 0; return 0;

View File

@ -908,10 +908,10 @@ int SELECTION_TOOL::selectSameSheet( const TOOL_EVENT& aEvent )
// on one sheet. // on one sheet.
auto item = m_selection.Front(); auto item = m_selection.Front();
if( item->Type() != PCB_MODULE_T ) if( !item )
return 0; return 0;
if( !item ) if( item->Type() != PCB_MODULE_T )
return 0; return 0;
auto mod = dynamic_cast<MODULE*>( item ); auto mod = dynamic_cast<MODULE*>( item );
@ -1509,6 +1509,9 @@ static double calcMaxArea( GENERAL_COLLECTOR& aCollector, KICAD_T aType )
static inline double calcCommonArea( const BOARD_ITEM* aItem, const BOARD_ITEM* aOther ) static inline double calcCommonArea( const BOARD_ITEM* aItem, const BOARD_ITEM* aOther )
{ {
if( !aItem || !aOther )
return 0;
return getRect( aItem ).Common( getRect( aOther ) ).GetArea(); return getRect( aItem ).Common( getRect( aOther ) ).GetArea();
} }
@ -1697,7 +1700,7 @@ void SELECTION_TOOL::guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) c
for( int i = 0; i < aCollector.GetCount(); ++i ) for( int i = 0; i < aCollector.GetCount(); ++i )
{ {
if( TRACK* track = dyn_cast<TRACK*> ( aCollector[i] ) ) if( TRACK* track = dyn_cast<TRACK*>( aCollector[i] ) )
{ {
maxLength = std::max( track->GetLength(), maxLength ); maxLength = std::max( track->GetLength(), maxLength );
maxLength = std::max( (double) track->GetWidth(), maxLength ); maxLength = std::max( (double) track->GetWidth(), maxLength );