From db7dba96ad56885fb26ce077900f897c87e4330b Mon Sep 17 00:00:00 2001
From: jean-pierre charras <jp.charras@wanadoo.fr>
Date: Thu, 3 Jan 2019 17:49:25 +0100
Subject: [PATCH] Fix a few Coverity warnings.

Mainly not initialized members, and replace not tested dynamic_cast by static_cast.
---
 common/dialogs/dialog_edit_library_tables.cpp |  3 ++-
 common/gal/cairo/cairo_print.cpp              |  1 +
 eeschema/eeschema_config.cpp                  |  2 +-
 eeschema/lib_pin.cpp                          |  2 +-
 eeschema/libedit/block_libedit.cpp            | 10 ++++-----
 eeschema/libedit/lib_edit_frame.cpp           |  4 ++--
 eeschema/sch_painter.cpp                      |  8 +++++--
 eeschema/sch_screen.cpp                       |  3 +++
 include/legacy_gal/class_drawpanel.h          | 21 ++++++++++++++++++-
 pcbnew/dialogs/dialog_position_relative.cpp   |  7 ++++---
 pcbnew/dialogs/panel_setup_layers.cpp         |  4 ++--
 11 files changed, 47 insertions(+), 18 deletions(-)

diff --git a/common/dialogs/dialog_edit_library_tables.cpp b/common/dialogs/dialog_edit_library_tables.cpp
index 7f357d2920..250d498240 100644
--- a/common/dialogs/dialog_edit_library_tables.cpp
+++ b/common/dialogs/dialog_edit_library_tables.cpp
@@ -27,7 +27,8 @@ DIALOG_EDIT_LIBRARY_TABLES::DIALOG_EDIT_LIBRARY_TABLES( wxWindow* aParent,
         DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxDefaultSize,
                      wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
         m_GlobalTableChanged( false ),
-        m_ProjectTableChanged( false )
+        m_ProjectTableChanged( false ),
+        m_contentPanel( nullptr )
 {
     // Construction delayed until after panel is installed
 }
diff --git a/common/gal/cairo/cairo_print.cpp b/common/gal/cairo/cairo_print.cpp
index 2f558314a0..a14b4c1223 100644
--- a/common/gal/cairo/cairo_print.cpp
+++ b/common/gal/cairo/cairo_print.cpp
@@ -120,6 +120,7 @@ CAIRO_PRINT_GAL::CAIRO_PRINT_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions,
     cairo_reference( context );
     cairo_surface_reference( surface );
     m_clearColor = COLOR4D( 1.0, 1.0, 1.0, 1.0 );
+    m_hasNativeLandscapeRotation = false;
     resetContext();
     SetScreenDPI( m_printCtx->GetNativeDPI() );
 }
diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp
index 2c741ee4c2..27c4f1e713 100644
--- a/eeschema/eeschema_config.cpp
+++ b/eeschema/eeschema_config.cpp
@@ -447,7 +447,7 @@ void SCH_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg )
         }
     }
 
-    auto painter = dynamic_cast<KIGFX::SCH_PAINTER*>( GetCanvas()->GetView()->GetPainter() );
+    auto painter = static_cast<KIGFX::SCH_PAINTER*>( GetCanvas()->GetView()->GetPainter() );
     KIGFX::SCH_RENDER_SETTINGS* settings = painter->GetSettings();
     settings->m_ShowPinsElectricalType = false;
     settings->m_ShowHiddenText = false;
diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp
index fc77240ce5..4e89190fee 100644
--- a/eeschema/lib_pin.cpp
+++ b/eeschema/lib_pin.cpp
@@ -607,7 +607,7 @@ void LIB_PIN::drawGraphic( EDA_DRAW_PANEL*  aPanel,
             EDA_DRAW_FRAME* frame = aPanel->GetParent();
 
             if( frame->IsType( FRAME_SCH ) )
-                drawHidden = dynamic_cast<SCH_EDIT_FRAME*>( frame )->GetShowAllPins();
+                drawHidden = static_cast<SCH_EDIT_FRAME*>( frame )->GetShowAllPins();
             else if( frame->IsType( FRAME_SCH_LIB_EDITOR ) )
                 drawHidden = true;      // must be able to edit
         }
diff --git a/eeschema/libedit/block_libedit.cpp b/eeschema/libedit/block_libedit.cpp
index aaeb84f301..f8de2be152 100644
--- a/eeschema/libedit/block_libedit.cpp
+++ b/eeschema/libedit/block_libedit.cpp
@@ -101,7 +101,7 @@ void LIB_EDIT_FRAME::BlockMoveSelectedItems( const wxPoint& aOffset, LIB_PART* a
         item.ClearFlags();
     }
 
-    // view update    
+    // view update
 }
 
 
@@ -140,7 +140,7 @@ void LIB_EDIT_FRAME::BlockCopySelectedItems( const wxPoint& aOffset, LIB_PART* a
 
     for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
     {
-        oldItem = dynamic_cast<LIB_ITEM*>( aItemsList.GetPickedItem( ii ) );
+        oldItem = static_cast<LIB_ITEM*>( aItemsList.GetPickedItem( ii ) );
 
         // We *do not* copy fields because they are unique for the whole component
         // so skip them (do not duplicate) if they are flagged selected.
@@ -388,7 +388,7 @@ bool LIB_EDIT_FRAME::HandleBlockEnd( wxDC* aDC )
     {
         if( block->GetCommand() != BLOCK_SELECT_ITEMS_ONLY && GetCurPart() )
             BlockClearSelectedItems( GetCurPart(), block );
-                
+
         GetScreen()->ClearBlockCommand();
         GetScreen()->SetCurItem( NULL );
         m_canvas->EndMouseCapture( GetToolId(), GetGalCanvas()->GetCurrentCursor(), wxEmptyString,
@@ -461,7 +461,7 @@ void LIB_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
     block->SetCommand( BLOCK_IDLE );
     GetScreen()->SetCurItem( NULL );
     m_canvas->EndMouseCapture( GetToolId(), GetGalCanvas()->GetCurrentCursor(), wxEmptyString, false );
-    
+
     GetCanvas()->GetView()->ClearPreview();
     GetCanvas()->GetView()->ClearHiddenFlags();
 }
@@ -566,7 +566,7 @@ void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
         return;
 
     block->SetMoveVector( frame->GetCrossHairPosition( true ) - block->GetLastCursorPosition() );
-    
+
     preview->Clear();
     view->SetVisible( preview, true );
 
diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp
index c2fb67869b..81c453d59d 100644
--- a/eeschema/libedit/lib_edit_frame.cpp
+++ b/eeschema/libedit/lib_edit_frame.cpp
@@ -1195,7 +1195,7 @@ void LIB_EDIT_FRAME::OnRotate( wxCommandEvent& aEvent )
 
         for( unsigned ii = 0; ii < block.GetCount(); ii++ )
         {
-            item = dynamic_cast<LIB_ITEM*>( block.GetItem( ii ) );
+            item = static_cast<LIB_ITEM*>( block.GetItem( ii ) );
             item->Rotate( rotationPoint );
         }
 
@@ -1254,7 +1254,7 @@ void LIB_EDIT_FRAME::OnOrient( wxCommandEvent& aEvent )
 
         for( unsigned ii = 0; ii < block.GetCount(); ii++ )
         {
-            item = dynamic_cast<LIB_ITEM*>( block.GetItem( ii ) );
+            item = static_cast<LIB_ITEM*>( block.GetItem( ii ) );
 
             if( aEvent.GetId() == ID_LIBEDIT_MIRROR_Y || aEvent.GetId() == ID_POPUP_MIRROR_Y_BLOCK )
                 item->MirrorHorizontal( mirrorPoint );
diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp
index 78bad740f3..84c7075081 100644
--- a/eeschema/sch_painter.cpp
+++ b/eeschema/sch_painter.cpp
@@ -60,10 +60,14 @@ namespace KIGFX
 {
 
 SCH_RENDER_SETTINGS::SCH_RENDER_SETTINGS() :
-    m_ShowUnit( 0 ),
-    m_ShowConvert( 0 )
+    m_ShowUnit( 0 ), m_ShowConvert( 0 )
 {
     ImportLegacyColors( nullptr );
+
+    m_ShowHiddenText = true;
+    m_ShowHiddenPins = true;
+    m_ShowPinsElectricalType = true;
+    m_ShowUmbilicals = true;
 }
 
 
diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp
index bd2e3705b2..ef05a2f2e0 100644
--- a/eeschema/sch_screen.cpp
+++ b/eeschema/sch_screen.cpp
@@ -1532,6 +1532,9 @@ size_t SCH_SCREENS::GetLibNicknames( wxArrayString& aLibNicknames )
             symbol = dynamic_cast< SCH_COMPONENT* >( item );
             wxASSERT( symbol );
 
+            if( !symbol )
+                continue;
+
             nickname = symbol->GetLibId().GetLibNickname();
 
             if( !nickname.empty() && ( aLibNicknames.Index( nickname ) == wxNOT_FOUND ) )
diff --git a/include/legacy_gal/class_drawpanel.h b/include/legacy_gal/class_drawpanel.h
index e0917c1f01..70dfd11a90 100644
--- a/include/legacy_gal/class_drawpanel.h
+++ b/include/legacy_gal/class_drawpanel.h
@@ -84,7 +84,26 @@ protected:
 
 public:
 
-    EDA_DRAW_PANEL(){};
+    EDA_DRAW_PANEL() :
+        m_showCrossHair( true ),
+        m_cursorLevel( 0 ),
+        m_scrollIncrementX( 1 ),
+        m_scrollIncrementY( 1 ),
+        m_abortRequest( false ),
+        m_enableZoomNoCenter( false ),
+        m_enableMousewheelPan( false ),
+        m_enableAutoPan( false ),
+        m_ignoreMouseEvents( false ),
+        m_ignoreNextLeftButtonRelease( false ),
+        m_enableBlockCommands( true ),
+        m_minDragEventCount( 5 ),
+        m_PrintIsMirrored( false ),
+        m_mouseCaptureCallback( nullptr ),
+        m_endMouseCaptureCallback( nullptr ),
+        m_canStartBlock( true ),
+        m_doubleClickInterval( 0 )
+    {};
+
     virtual ~EDA_DRAW_PANEL(){};
 
     /**
diff --git a/pcbnew/dialogs/dialog_position_relative.cpp b/pcbnew/dialogs/dialog_position_relative.cpp
index 782d605509..a19e8c0acb 100644
--- a/pcbnew/dialogs/dialog_position_relative.cpp
+++ b/pcbnew/dialogs/dialog_position_relative.cpp
@@ -183,11 +183,12 @@ void DIALOG_POSITION_RELATIVE::OnUseUserOriginClick( wxCommandEvent& event )
 void DIALOG_POSITION_RELATIVE::UpdateAnchor( EDA_ITEM* aItem )
 {
     wxString reference = _( "<none selected>" );
+    BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( aItem );
 
-    if( aItem )
+    if( item )
     {
-        m_anchor_position = dynamic_cast<BOARD_ITEM*>( aItem )->GetPosition();
-        reference = aItem->GetSelectMenuText( GetUserUnits() );
+        m_anchor_position = item->GetPosition();
+        reference = item->GetSelectMenuText( GetUserUnits() );
     }
 
     m_referenceInfo->SetLabel( wxString::Format( "Reference item: %s", reference ) );
diff --git a/pcbnew/dialogs/panel_setup_layers.cpp b/pcbnew/dialogs/panel_setup_layers.cpp
index 5262fae153..0bc48a56d8 100644
--- a/pcbnew/dialogs/panel_setup_layers.cpp
+++ b/pcbnew/dialogs/panel_setup_layers.cpp
@@ -598,9 +598,9 @@ wxString PANEL_SETUP_LAYERS::getLayerName( LAYER_NUM aLayer )
     wxControl* control = getName( aLayer );
 
     if( dynamic_cast<wxTextCtrl*>( control ) )
-        return dynamic_cast<wxTextCtrl*>( control )->GetValue().Trim();
+        return static_cast<wxTextCtrl*>( control )->GetValue().Trim();
     else
-        return dynamic_cast<wxStaticText*>( control )->GetLabel();
+        return static_cast<wxStaticText*>( control )->GetLabel();
 }