Coverity fixes.

This commit is contained in:
Jeff Young 2021-10-16 16:27:19 +01:00
parent c4e775c694
commit a1c1f60665
1 changed files with 29 additions and 39 deletions

View File

@ -907,17 +907,20 @@ LIB_SHAPE* SCH_SEXPR_PARSER::parseArc()
wxCHECK_MSG( CurTok() == T_arc, nullptr, wxCHECK_MSG( CurTok() == T_arc, nullptr,
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as an arc." ) ); wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as an arc." ) );
T token; T token;
wxPoint startPoint; wxPoint startPoint( 1, 0 ); // Initialize to a non-degenerate arc just for safety
wxPoint midPoint; wxPoint midPoint( 1, 1 );
wxPoint endPoint; wxPoint endPoint( 0, 1 );
wxPoint pos; bool hasMidPoint = false;
int startAngle;
int endAngle;
STROKE_PARAMS stroke( Mils2iu( DEFAULT_LINE_WIDTH_MILS ), PLOT_DASH_TYPE::DEFAULT ); STROKE_PARAMS stroke( Mils2iu( DEFAULT_LINE_WIDTH_MILS ), PLOT_DASH_TYPE::DEFAULT );
FILL_PARAMS fill; FILL_PARAMS fill;
bool hasMidPoint = false;
bool hasAngles = false; // Parameters for legacy format
wxPoint center( 0, 0 );
int startAngle = 0;
int endAngle = 900;
bool hasAngles = false;
std::unique_ptr<LIB_SHAPE> arc = std::make_unique<LIB_SHAPE>( nullptr, SHAPE_T::ARC ); std::unique_ptr<LIB_SHAPE> arc = std::make_unique<LIB_SHAPE>( nullptr, SHAPE_T::ARC );
arc->SetUnit( m_unit ); arc->SetUnit( m_unit );
@ -959,7 +962,7 @@ LIB_SHAPE* SCH_SEXPR_PARSER::parseArc()
switch( token ) switch( token )
{ {
case T_at: case T_at:
pos = parseXY(); center = parseXY();
NeedRIGHT(); NeedRIGHT();
break; break;
@ -1006,9 +1009,7 @@ LIB_SHAPE* SCH_SEXPR_PARSER::parseArc()
if( hasMidPoint ) if( hasMidPoint )
{ {
VECTOR2I center = CalcArcCenter( arc->GetStart(), midPoint, arc->GetEnd() ); arc->SetCenter( (wxPoint) CalcArcCenter( arc->GetStart(), midPoint, arc->GetEnd() ) );
arc->SetCenter( (wxPoint) center );
} }
else if( hasAngles ) else if( hasAngles )
{ {
@ -1025,7 +1026,7 @@ LIB_SHAPE* SCH_SEXPR_PARSER::parseArc()
arc->SetStart( arc->GetEnd() ); arc->SetStart( arc->GetEnd() );
arc->SetEnd( temp ); arc->SetEnd( temp );
} }
arc->SetCenter( pos ); arc->SetCenter( center );
} }
else else
{ {
@ -1041,9 +1042,10 @@ LIB_SHAPE* SCH_SEXPR_PARSER::parseBezier()
wxCHECK_MSG( CurTok() == T_bezier, nullptr, wxCHECK_MSG( CurTok() == T_bezier, nullptr,
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a bezier." ) ); wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a bezier." ) );
T token; T token;
STROKE_PARAMS stroke( Mils2iu( DEFAULT_LINE_WIDTH_MILS ), PLOT_DASH_TYPE::DEFAULT ); STROKE_PARAMS stroke( Mils2iu( DEFAULT_LINE_WIDTH_MILS ), PLOT_DASH_TYPE::DEFAULT );
FILL_PARAMS fill; FILL_PARAMS fill;
std::unique_ptr<LIB_SHAPE> bezier = std::make_unique<LIB_SHAPE>( nullptr, SHAPE_T::BEZIER ); std::unique_ptr<LIB_SHAPE> bezier = std::make_unique<LIB_SHAPE>( nullptr, SHAPE_T::BEZIER );
bezier->SetUnit( m_unit ); bezier->SetUnit( m_unit );
@ -1100,11 +1102,12 @@ LIB_SHAPE* SCH_SEXPR_PARSER::parseCircle()
wxCHECK_MSG( CurTok() == T_circle, nullptr, wxCHECK_MSG( CurTok() == T_circle, nullptr,
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a circle." ) ); wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a circle." ) );
T token; T token;
wxPoint center; wxPoint center( 0, 0 );
int radius; int radius = 1; // defaulting to 0 could result in troublesome math....
STROKE_PARAMS stroke( Mils2iu( DEFAULT_LINE_WIDTH_MILS ), PLOT_DASH_TYPE::DEFAULT ); STROKE_PARAMS stroke( Mils2iu( DEFAULT_LINE_WIDTH_MILS ), PLOT_DASH_TYPE::DEFAULT );
FILL_PARAMS fill; FILL_PARAMS fill;
std::unique_ptr<LIB_SHAPE> circle = std::make_unique<LIB_SHAPE>( nullptr, SHAPE_T::CIRCLE ); std::unique_ptr<LIB_SHAPE> circle = std::make_unique<LIB_SHAPE>( nullptr, SHAPE_T::CIRCLE );
circle->SetUnit( m_unit ); circle->SetUnit( m_unit );
@ -1239,24 +1242,11 @@ LIB_PIN* SCH_SEXPR_PARSER::parsePin()
switch( parseInt( "pin orientation" ) ) switch( parseInt( "pin orientation" ) )
{ {
case 0: case 0: pin->SetOrientation( PIN_RIGHT ); break;
pin->SetOrientation( PIN_RIGHT ); case 90: pin->SetOrientation( PIN_UP ); break;
break; case 180: pin->SetOrientation( PIN_LEFT ); break;
case 270: pin->SetOrientation( PIN_DOWN ); break;
case 90: default: Expecting( "0, 90, 180, or 270" );
pin->SetOrientation( PIN_UP );
break;
case 180:
pin->SetOrientation( PIN_LEFT );
break;
case 270:
pin->SetOrientation( PIN_DOWN );
break;
default:
Expecting( "0, 90, 180, or 270" );
} }
NeedRIGHT(); NeedRIGHT();