From 095d0a27d02a0a9b18449aded7f932566b6f5968 Mon Sep 17 00:00:00 2001
From: Mark Roszko <mark.roszko@gmail.com>
Date: Sat, 6 Jan 2018 00:02:28 -0500
Subject: [PATCH] Some coverity fixes

---
 3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.cpp | 1 +
 common/gal/opengl/opengl_gal.cpp                              | 3 ++-
 eeschema/cmp_tree_model.cpp                                   | 3 ++-
 eeschema/lib_manager.cpp                                      | 2 +-
 eeschema/sch_screen.cpp                                       | 3 +++
 eeschema/sim/sim_plot_frame.cpp                               | 3 +--
 gerbview/gerbview_painter.cpp                                 | 2 +-
 gerbview/gerbview_painter.h                                   | 2 +-
 include/class_eda_rect.h                                      | 2 ++
 include/eagle_parser.h                                        | 3 ++-
 include/preview_items/arc_geom_manager.h                      | 2 +-
 include/tool/coroutine.h                                      | 3 ++-
 pcbnew/connectivity_data.cpp                                  | 1 +
 pcbnew/footprint_info_impl.cpp                                | 2 +-
 pcbnew/import_dxf/dxf2brd_items.cpp                           | 1 +
 15 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.cpp b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.cpp
index 9215bfe5d..993219e3b 100644
--- a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.cpp
+++ b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.cpp
@@ -37,6 +37,7 @@
 C_OGL_3DMODEL::C_OGL_3DMODEL( const S3DMODEL &a3DModel,
                               MATERIAL_MODE aMaterialMode )
 {
+    m_ogl_idx_list_meshes = 0;
     m_ogl_idx_list_opaque = 0;
     m_ogl_idx_list_transparent = 0;
     m_nr_meshes = 0;
diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp
index 66b696fd8..729c103c8 100644
--- a/common/gal/opengl/opengl_gal.cpp
+++ b/common/gal/opengl/opengl_gal.cpp
@@ -71,7 +71,7 @@ OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent,
     HIDPI_GL_CANVAS( aParent, wxID_ANY, (int*) glAttributes, wxDefaultPosition, wxDefaultSize,
                 wxEXPAND, aName ),
     mouseListener( aMouseListener ), paintListener( aPaintListener ), currentManager( nullptr ),
-    cachedManager( nullptr ), nonCachedManager( nullptr ), overlayManager( nullptr )
+    cachedManager( nullptr ), nonCachedManager( nullptr ), overlayManager( nullptr ), mainBuffer( 0 ), overlayBuffer( 0 )
 {
     if( glMainContext == NULL )
     {
@@ -1583,6 +1583,7 @@ int OPENGL_GAL::drawBitmapChar( unsigned long aChar )
     if( aChar == ' ' )
     {
         const FONT_GLYPH_TYPE* g = LookupGlyph( 'x' );
+        wxASSERT( g );
         Translate( VECTOR2D( g->advance, 0 ) );
         return g->advance;
     }
diff --git a/eeschema/cmp_tree_model.cpp b/eeschema/cmp_tree_model.cpp
index 335339d76..99ba26c05 100644
--- a/eeschema/cmp_tree_model.cpp
+++ b/eeschema/cmp_tree_model.cpp
@@ -107,7 +107,8 @@ CMP_TREE_NODE::CMP_TREE_NODE()
         Type( INVALID ),
         IntrinsicRank( 0 ),
         Score( kLowestDefaultScore ),
-        Unit( 0 )
+        Unit( 0 ),
+        IsRoot( false )
 {}
 
 
diff --git a/eeschema/lib_manager.cpp b/eeschema/lib_manager.cpp
index 9c5077c94..da7e7ad50 100644
--- a/eeschema/lib_manager.cpp
+++ b/eeschema/lib_manager.cpp
@@ -35,7 +35,7 @@
 
 
 LIB_MANAGER::LIB_MANAGER( LIB_EDIT_FRAME& aFrame )
-    : m_frame( aFrame ), m_symbolTable( aFrame.Prj().SchSymbolLibTable() )
+    : m_frame( aFrame ), m_symbolTable( aFrame.Prj().SchSymbolLibTable() ), m_syncHash( 0 )
 {
     m_adapter = LIB_MANAGER_ADAPTER::Create( this );
     m_adapter->ShowUnits( false );
diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp
index acfb75b32..a212b73b4 100644
--- a/eeschema/sch_screen.cpp
+++ b/eeschema/sch_screen.cpp
@@ -1462,6 +1462,7 @@ bool SCH_SCREENS::HasNoFullyDefinedLibIds()
 
             cnt += 1;
             symbol = dynamic_cast< SCH_COMPONENT* >( item );
+            wxASSERT( symbol );
 
             if( !symbol->GetLibId().GetLibNickname().empty() )
                 return false;
@@ -1493,6 +1494,7 @@ size_t SCH_SCREENS::GetLibNicknames( wxArrayString& aLibNicknames )
                 continue;
 
             symbol = dynamic_cast< SCH_COMPONENT* >( item );
+            wxASSERT( symbol );
 
             nickname = symbol->GetLibId().GetLibNickname();
 
@@ -1523,6 +1525,7 @@ int SCH_SCREENS::ChangeSymbolLibNickname( const wxString& aFrom, const wxString&
                 continue;
 
             symbol = dynamic_cast< SCH_COMPONENT* >( item );
+            wxASSERT( symbol );
 
             if( symbol->GetLibId().GetLibNickname() != aFrom )
                 continue;
diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp
index c7cb7bd80..96f8ac47a 100644
--- a/eeschema/sim/sim_plot_frame.cpp
+++ b/eeschema/sim/sim_plot_frame.cpp
@@ -905,8 +905,7 @@ void SIM_PLOT_FRAME::menuShowGridUpdate( wxUpdateUIEvent& event )
 {
     SIM_PLOT_PANEL* plot = CurrentPlot();
 
-    if( plot )
-        event.Check( plot ? plot->IsGridShown() : false );
+    event.Check( plot ? plot->IsGridShown() : false );
 }
 
 
diff --git a/gerbview/gerbview_painter.cpp b/gerbview/gerbview_painter.cpp
index 7ac870ff5..0da940094 100644
--- a/gerbview/gerbview_painter.cpp
+++ b/gerbview/gerbview_painter.cpp
@@ -383,7 +383,7 @@ void GERBVIEW_PAINTER::draw( /*const*/ GERBER_DRAW_ITEM* aItem, int aLayer )
 
 
 void GERBVIEW_PAINTER::drawPolygon( GERBER_DRAW_ITEM* aParent,
-                                    SHAPE_POLY_SET aPolygon,
+                                    SHAPE_POLY_SET& aPolygon,
                                     bool aFilled )
 {
     for( auto it = aPolygon.Iterate( 0 ); it; ++it )
diff --git a/gerbview/gerbview_painter.h b/gerbview/gerbview_painter.h
index b167bb49a..e27352e18 100644
--- a/gerbview/gerbview_painter.h
+++ b/gerbview/gerbview_painter.h
@@ -181,7 +181,7 @@ protected:
     void draw( /*const*/ GERBER_DRAW_ITEM* aVia, int aLayer );
 
     /// Helper routine to draw a polygon
-    void drawPolygon( GERBER_DRAW_ITEM* aParent, SHAPE_POLY_SET aPolygon, bool aFilled );
+    void drawPolygon( GERBER_DRAW_ITEM* aParent, SHAPE_POLY_SET& aPolygon, bool aFilled );
 
     /// Helper to draw a flashed shape (aka spot)
     void drawFlashedShape( GERBER_DRAW_ITEM* aItem, bool aFilled );
diff --git a/include/class_eda_rect.h b/include/class_eda_rect.h
index c6b0acfe4..cd9a0ab46 100644
--- a/include/class_eda_rect.h
+++ b/include/class_eda_rect.h
@@ -55,6 +55,8 @@ public:
         m_Size( aSize )
     { }
 
+    virtual ~EDA_RECT() { };
+
     wxPoint Centre() const
     {
         return wxPoint( m_Pos.x + ( m_Size.x >> 1 ),
diff --git a/include/eagle_parser.h b/include/eagle_parser.h
index 0492a42ef..173ad5421 100644
--- a/include/eagle_parser.h
+++ b/include/eagle_parser.h
@@ -199,7 +199,8 @@ public:
      * construct a default OPTIONAL_XML_ATTRIBUTE, whose data is not available.
      */
     OPTIONAL_XML_ATTRIBUTE() :
-	   m_isAvailable( false )
+        m_isAvailable( false ),
+        m_data( T() )
     {}
 
     /**
diff --git a/include/preview_items/arc_geom_manager.h b/include/preview_items/arc_geom_manager.h
index c563b486f..7eb393fd5 100644
--- a/include/preview_items/arc_geom_manager.h
+++ b/include/preview_items/arc_geom_manager.h
@@ -135,7 +135,7 @@ private:
     /*
      * construction parameters
      */
-    bool m_angleSnap;
+    bool m_angleSnap = false;
 };
 }       // PREVIEW
 }       // KIGFX
diff --git a/include/tool/coroutine.h b/include/tool/coroutine.h
index 750432909..d55e9858f 100644
--- a/include/tool/coroutine.h
+++ b/include/tool/coroutine.h
@@ -136,7 +136,8 @@ public:
         m_running( false ),
         m_args( 0 ),
         m_callee( nullptr ),
-        m_retVal( 0 )
+        m_retVal( 0 ),
+        m_callContext( nullptr )
     {
     }
 
diff --git a/pcbnew/connectivity_data.cpp b/pcbnew/connectivity_data.cpp
index 99ca7cd37..3ce92e276 100644
--- a/pcbnew/connectivity_data.cpp
+++ b/pcbnew/connectivity_data.cpp
@@ -36,6 +36,7 @@
 CONNECTIVITY_DATA::CONNECTIVITY_DATA()
 {
     m_connAlgo.reset( new CN_CONNECTIVITY_ALGO );
+    m_progressReporter = nullptr;
 }
 
 
diff --git a/pcbnew/footprint_info_impl.cpp b/pcbnew/footprint_info_impl.cpp
index db2d3788a..23743ff99 100644
--- a/pcbnew/footprint_info_impl.cpp
+++ b/pcbnew/footprint_info_impl.cpp
@@ -244,7 +244,7 @@ size_t FOOTPRINT_LIST_IMPL::CountFinished()
 }
 
 
-FOOTPRINT_LIST_IMPL::FOOTPRINT_LIST_IMPL() : m_loader( nullptr )
+FOOTPRINT_LIST_IMPL::FOOTPRINT_LIST_IMPL() : m_loader( nullptr ), m_first_to_finish( false ), m_count_finished( 0 )
 {
 }
 
diff --git a/pcbnew/import_dxf/dxf2brd_items.cpp b/pcbnew/import_dxf/dxf2brd_items.cpp
index 96f36df4b..b02438630 100644
--- a/pcbnew/import_dxf/dxf2brd_items.cpp
+++ b/pcbnew/import_dxf/dxf2brd_items.cpp
@@ -60,6 +60,7 @@ DXF2BRD_CONVERTER::DXF2BRD_CONVERTER() : DRW_Interface()
     m_yOffset   = 0.0;          // Y coord offset for conversion (in mm)
     m_DXF2mm    = 1.0;          // The scale factor to convert DXF units to mm
     m_version   = 0;            // the dxf version, not yet used
+    m_defaultThickness = 0.2;   // default thickness (in mm)
     m_brdLayer = Dwgs_User;     // The default import layer
     m_importAsfootprintGraphicItems = true;
 }
-- 
2.15.1.windows.2

