From a1c1f6066538e9573e93b27fa5ba12dffe0a4d1d Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 16 Oct 2021 16:27:19 +0100 Subject: [PATCH] Coverity fixes. --- .../sch_plugins/kicad/sch_sexpr_parser.cpp | 68 ++++++++----------- 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index 1566fa3d87..953b735b90 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -907,17 +907,20 @@ LIB_SHAPE* SCH_SEXPR_PARSER::parseArc() wxCHECK_MSG( CurTok() == T_arc, nullptr, wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as an arc." ) ); - T token; - wxPoint startPoint; - wxPoint midPoint; - wxPoint endPoint; - wxPoint pos; - int startAngle; - int endAngle; + T token; + wxPoint startPoint( 1, 0 ); // Initialize to a non-degenerate arc just for safety + wxPoint midPoint( 1, 1 ); + wxPoint endPoint( 0, 1 ); + bool hasMidPoint = false; STROKE_PARAMS stroke( Mils2iu( DEFAULT_LINE_WIDTH_MILS ), PLOT_DASH_TYPE::DEFAULT ); - FILL_PARAMS fill; - bool hasMidPoint = false; - bool hasAngles = false; + FILL_PARAMS fill; + + // Parameters for legacy format + wxPoint center( 0, 0 ); + int startAngle = 0; + int endAngle = 900; + bool hasAngles = false; + std::unique_ptr arc = std::make_unique( nullptr, SHAPE_T::ARC ); arc->SetUnit( m_unit ); @@ -959,7 +962,7 @@ LIB_SHAPE* SCH_SEXPR_PARSER::parseArc() switch( token ) { case T_at: - pos = parseXY(); + center = parseXY(); NeedRIGHT(); break; @@ -1006,9 +1009,7 @@ LIB_SHAPE* SCH_SEXPR_PARSER::parseArc() if( hasMidPoint ) { - VECTOR2I center = CalcArcCenter( arc->GetStart(), midPoint, arc->GetEnd() ); - - arc->SetCenter( (wxPoint) center ); + arc->SetCenter( (wxPoint) CalcArcCenter( arc->GetStart(), midPoint, arc->GetEnd() ) ); } else if( hasAngles ) { @@ -1025,7 +1026,7 @@ LIB_SHAPE* SCH_SEXPR_PARSER::parseArc() arc->SetStart( arc->GetEnd() ); arc->SetEnd( temp ); } - arc->SetCenter( pos ); + arc->SetCenter( center ); } else { @@ -1041,9 +1042,10 @@ LIB_SHAPE* SCH_SEXPR_PARSER::parseBezier() wxCHECK_MSG( CurTok() == T_bezier, nullptr, 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 ); - FILL_PARAMS fill; + FILL_PARAMS fill; + std::unique_ptr bezier = std::make_unique( nullptr, SHAPE_T::BEZIER ); bezier->SetUnit( m_unit ); @@ -1100,11 +1102,12 @@ LIB_SHAPE* SCH_SEXPR_PARSER::parseCircle() wxCHECK_MSG( CurTok() == T_circle, nullptr, wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a circle." ) ); - T token; - wxPoint center; - int radius; + T token; + wxPoint center( 0, 0 ); + int radius = 1; // defaulting to 0 could result in troublesome math.... STROKE_PARAMS stroke( Mils2iu( DEFAULT_LINE_WIDTH_MILS ), PLOT_DASH_TYPE::DEFAULT ); - FILL_PARAMS fill; + FILL_PARAMS fill; + std::unique_ptr circle = std::make_unique( nullptr, SHAPE_T::CIRCLE ); circle->SetUnit( m_unit ); @@ -1239,24 +1242,11 @@ LIB_PIN* SCH_SEXPR_PARSER::parsePin() switch( parseInt( "pin orientation" ) ) { - case 0: - pin->SetOrientation( PIN_RIGHT ); - break; - - case 90: - 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" ); + case 0: pin->SetOrientation( PIN_RIGHT ); break; + case 90: 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();