Coverity fixes

resource leak: #172233
negative array index write: #102363
uninitialized scalar field: #174540 #174539
structurally dead code: #169334 #169331
This commit is contained in:
Maciej Suminski 2018-03-19 10:02:05 +01:00
parent 4e76a18d5d
commit ce610f33a2
6 changed files with 22 additions and 35 deletions

View File

@ -68,7 +68,7 @@ void TEXTE_PCB::SetTextAngle( double aAngle )
void TEXTE_PCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
GR_DRAWMODE DrawMode, const wxPoint& offset )
{
wxASSERT( panel );
wxASSERT( panel );
if( !panel )
return;
@ -78,16 +78,11 @@ void TEXTE_PCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
if( brd->IsLayerVisible( m_Layer ) == false )
return;
auto frame = static_cast<PCB_EDIT_FRAME*> ( panel->GetParent() );
auto frame = static_cast<PCB_EDIT_FRAME*>( panel->GetParent() );
auto color = frame->Settings().Colors().GetLayerColor( m_Layer );
EDA_DRAW_MODE_T fillmode = FILLED;
PCB_DISPLAY_OPTIONS* displ_opts = nullptr;
if( panel )
{
displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
}
PCB_DISPLAY_OPTIONS* displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
if( displ_opts && displ_opts->m_DisplayDrawItemsFill == SKETCH )
fillmode = SKETCH;
@ -106,8 +101,7 @@ void TEXTE_PCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
if( brd->IsElementVisible( LAYER_ANCHOR ) )
anchor_color = frame->Settings().Colors().GetItemColor( LAYER_ANCHOR );
EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
EDA_TEXT::Draw( clipbox, DC, offset, color,
EDA_TEXT::Draw( panel->GetClipBox(), DC, offset, color,
DrawMode, fillmode, anchor_color );
// Enable these line to draw the bounding box (debug tests purposes only)

View File

@ -55,6 +55,9 @@ ZONE_CONTAINER::ZONE_CONTAINER( BOARD* aBoard ) :
m_CornerSelection = nullptr; // no corner is selected
m_IsFilled = false; // fill status : true when the zone is filled
m_FillMode = ZFM_POLYGONS;
m_hatchStyle = DIAGONAL_EDGE;
m_hatchPitch = GetDefaultHatchPitch();
m_hv45 = false;
m_priority = 0;
m_cornerSmoothingType = ZONE_SETTINGS::SMOOTHING_NONE;
SetIsKeepout( false );

View File

@ -108,9 +108,11 @@ public:
ROW()
{
spacer = true;
color = COLOR4D::UNSPECIFIED;
id = 0;
color = COLOR4D::UNSPECIFIED;
state = true;
changeable = true;
spacer = true;
}
};

View File

@ -134,25 +134,6 @@ const BOX2I SELECTION::ViewBBox() const
BOX2I r;
r.SetMaximum();
return r;
EDA_RECT eda_bbox;
if( Size() == 1 )
{
eda_bbox = Front()->GetBoundingBox();
}
else if( Size() > 1 )
{
eda_bbox = Front()->GetBoundingBox();
auto i = m_items.begin();
++i;
for( ; i != m_items.end(); ++i )
{
eda_bbox.Merge( (*i)->GetBoundingBox() );
}
}
return BOX2I( eda_bbox.GetOrigin(), eda_bbox.GetSize() );
}

View File

@ -736,6 +736,10 @@ Triangle& Sweep::NextFlipTriangle(SweepContext& tcx, int o, Triangle& t, Triangl
if (o == CCW) {
// ot is not crossing edge after flip
int edge_index = ot.EdgeIndex(&p, &op);
if(edge_index < 0)
throw std::runtime_error("Edge not found in the triangle");
ot.delaunay_edge[edge_index] = true;
Legalize(tcx, ot);
ot.ClearDelunayEdges();
@ -745,6 +749,9 @@ Triangle& Sweep::NextFlipTriangle(SweepContext& tcx, int o, Triangle& t, Triangl
// t is not crossing edge after flip
int edge_index = t.EdgeIndex(&p, &op);
if(edge_index < 0)
throw std::runtime_error("Edge not found in the triangle");
t.delaunay_edge[edge_index] = true;
Legalize(tcx, t);
t.ClearDelunayEdges();

View File

@ -28,6 +28,7 @@
#include <iostream>
#include <sstream>
#include <string>
#include <memory>
#include "kicadpcb.h"
#include "sexpr/sexpr.h"
@ -143,9 +144,9 @@ bool KICADPCB::ReadFile( const wxString& aFileName )
{
SEXPR::PARSER parser;
std::string infile( fname.GetFullPath().ToUTF8() );
SEXPR::SEXPR* data = parser.ParseFromFile( infile );
std::unique_ptr<SEXPR::SEXPR> data( parser.ParseFromFile( infile ) );
if( NULL == data )
if( !data )
{
std::ostringstream ostr;
ostr << "* no data in file: '" << aFileName.ToUTF8() << "'\n";
@ -154,9 +155,8 @@ bool KICADPCB::ReadFile( const wxString& aFileName )
return false;
}
if( !parsePCB( data ) )
if( !parsePCB( data.get() ) )
return false;
}
catch( std::exception& e )
{