← Back to team overview

kicad-developers team mailing list archive

[PATCH] coverity /common/ fixes

 

Just misc fixes of errors in the /common/ folder from coverity. Namely
the initialization errors fixed by using initialization lists.

Also flipped the logic the keyword generator creates to shutup
coverity. It gets tricked by an signed -> unsigned conversion for a
single check
diff --git CMakeModules/TokenList2DsnLexer.cmake CMakeModules/TokenList2DsnLexer.cmake
index df2ea8a..80044aa 100644
--- CMakeModules/TokenList2DsnLexer.cmake
+++ CMakeModules/TokenList2DsnLexer.cmake
@@ -374,14 +374,10 @@ const char* ${LEXERCLASS}::TokenName( T aTok )
 {
     const char* ret;
 
-    if( (unsigned) aTok < keyword_count )
-    {
-        ret = keywords[aTok].name;
-    }
-    else if( aTok < 0 )
-    {
+    if( aTok < 0 )
         ret = DSNLEXER::Syntax( aTok );
-    }
+    else if( (unsigned)aTok < keyword_count )
+        ret = keywords[aTok].name;
     else
         ret = \"token too big\";
 
diff --git common/class_layer_box_selector.cpp common/class_layer_box_selector.cpp
index 885479a..75af073 100644
--- common/class_layer_box_selector.cpp
+++ common/class_layer_box_selector.cpp
@@ -35,10 +35,10 @@
 #include <class_layer_box_selector.h>
 
 
-LAYER_SELECTOR::LAYER_SELECTOR()
+LAYER_SELECTOR::LAYER_SELECTOR() :
+    m_layerhotkeys(true),
+    m_hotkeys(NULL)
 {
-    m_layerhotkeys = true;
-    m_hotkeys      = NULL;
 }
 
 
@@ -81,8 +81,6 @@ LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id,
 {
     if( choices != NULL )
         ResyncBitmapOnly();
-
-    m_hotkeys = NULL;
 }
 
 
diff --git common/common_plotHPGL_functions.cpp common/common_plotHPGL_functions.cpp
index 81b462d..5989223 100644
--- common/common_plotHPGL_functions.cpp
+++ common/common_plotHPGL_functions.cpp
@@ -201,7 +201,9 @@
 // HPGL scale factor (1 PLU = 1/40mm = 25 micrometers)
 static const double PLUsPERDECIMIL = 0.102041;
 
-HPGL_PLOTTER::HPGL_PLOTTER()
+HPGL_PLOTTER::HPGL_PLOTTER() :
+    penDiameter( 0 ),
+    penOverlap( 0 )
 {
     SetPenSpeed( 40 );      // Default pen speed = 40 cm/s
     SetPenNumber( 1 );      // Default pen num = 1
diff --git common/dsnlexer.cpp common/dsnlexer.cpp
index e6d9e93..7b83de2 100644
--- common/dsnlexer.cpp
+++ common/dsnlexer.cpp
@@ -77,7 +77,11 @@ DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
                     FILE* aFile, const wxString& aFilename ) :
     iOwnReaders( true ),
     keywords( aKeywordTable ),
-    keywordCount( aKeywordCount )
+    keywordCount( aKeywordCount ),
+    start(NULL),
+    next(NULL),
+    limit(NULL),
+    reader(NULL)
 {
     FILE_LINE_READER* fileReader = new FILE_LINE_READER( aFile, aFilename );
     PushReader( fileReader );
@@ -89,7 +93,11 @@ DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
                     const std::string& aClipboardTxt, const wxString& aSource ) :
     iOwnReaders( true ),
     keywords( aKeywordTable ),
-    keywordCount( aKeywordCount )
+    keywordCount( aKeywordCount ),
+    start(NULL),
+    next(NULL),
+    limit(NULL),
+    reader(NULL)
 {
     STRING_LINE_READER* stringReader = new STRING_LINE_READER( aClipboardTxt, aSource.IsEmpty() ?
                                         wxString( FMT_CLIPBOARD ) : aSource );
@@ -102,7 +110,11 @@ DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
                     LINE_READER* aLineReader ) :
     iOwnReaders( false ),
     keywords( aKeywordTable ),
-    keywordCount( aKeywordCount )
+    keywordCount( aKeywordCount ),
+    start(NULL),
+    next(NULL),
+    limit(NULL),
+    reader(NULL)
 {
     if( aLineReader )
         PushReader( aLineReader );
@@ -115,7 +127,11 @@ static const KEYWORD empty_keywords[1] = {};
 DSNLEXER::DSNLEXER( const std::string& aSExpression, const wxString& aSource ) :
     iOwnReaders( true ),
     keywords( empty_keywords ),
-    keywordCount( 0 )
+    keywordCount( 0 ),
+    start(NULL),
+    next(NULL),
+    limit(NULL),
+    reader(NULL)
 {
     STRING_LINE_READER* stringReader = new STRING_LINE_READER( aSExpression, aSource.IsEmpty() ?
                                         wxString( FMT_CLIPBOARD ) : aSource );
diff --git common/richio.cpp common/richio.cpp
index ec1cf8c..9df1e44 100644
--- common/richio.cpp
+++ common/richio.cpp
@@ -120,21 +120,15 @@ void PARSE_ERROR::init( const char* aThrowersFile, const char* aThrowersLoc,
 
 //-----<LINE_READER>------------------------------------------------------
 
-LINE_READER::LINE_READER( unsigned aMaxLineLength )
+LINE_READER::LINE_READER( unsigned aMaxLineLength ) :
+    length( 0 ),
+    lineNum( 0 ),
+    line( NULL ),
+    capacity( LINE_READER_LINE_INITIAL_SIZE ),  //initial size that can get expanded
+    maxLineLength( aMaxLineLength )
 {
-    lineNum = 0;
-
-    if( aMaxLineLength == 0 )
-    {
-        line = 0;
-    }
-    else
+    if( aMaxLineLength != 0 )
     {
-        maxLineLength = aMaxLineLength;
-
-        // start at the INITIAL size, expand as needed up to the MAX size in maxLineLength
-        capacity = LINE_READER_LINE_INITIAL_SIZE;
-
         // but never go above user's aMaxLineLength, and leave space for trailing nul
         if( capacity > aMaxLineLength+1 )
             capacity = aMaxLineLength+1;
@@ -143,8 +137,6 @@ LINE_READER::LINE_READER( unsigned aMaxLineLength )
 
         line[0] = '\0';
     }
-
-    length  = 0;
 }
 
 
diff --git common/tool/tool_dispatcher.cpp common/tool/tool_dispatcher.cpp
index 7166f65..7b3131e 100644
--- common/tool/tool_dispatcher.cpp
+++ common/tool/tool_dispatcher.cpp
@@ -42,6 +42,9 @@ struct TOOL_DISPATCHER::BUTTON_STATE
 {
     BUTTON_STATE( TOOL_MOUSE_BUTTONS aButton, const wxEventType& aDownEvent,
                  const wxEventType& aUpEvent, const wxEventType& aDblClickEvent ) :
+        dragging( false ),
+        pressed( false ),
+        dragMaxDelta( 0.0f ),
         button( aButton ),
         downEvent( aDownEvent ),
         upEvent( aUpEvent ),
diff --git common/tool/tool_manager.cpp common/tool/tool_manager.cpp
index 39ce08f..ff6ada4 100644
--- common/tool/tool_manager.cpp
+++ common/tool/tool_manager.cpp
@@ -195,7 +195,11 @@ private:
 
 
 TOOL_MANAGER::TOOL_MANAGER() :
-    m_model( NULL ), m_view( NULL ), m_viewControls( NULL ), m_editFrame( NULL )
+    m_model( NULL ),
+    m_view( NULL ),
+    m_viewControls( NULL ),
+    m_editFrame( NULL ),
+    m_passEvent( false )
 {
     m_actionMgr = new ACTION_MANAGER( this );
 
diff --git common/wx_unit_binder.cpp common/wx_unit_binder.cpp
index 90a66ae..9498d3a 100644
--- common/wx_unit_binder.cpp
+++ common/wx_unit_binder.cpp
@@ -35,13 +35,17 @@
 
 #include "wx_unit_binder.h"
 
-WX_UNIT_BINDER::WX_UNIT_BINDER( wxWindow* aParent, wxTextCtrl* aTextInput, wxStaticText* aUnitLabel, wxSpinButton* aSpinButton )
+WX_UNIT_BINDER::WX_UNIT_BINDER( wxWindow* aParent, wxTextCtrl* aTextInput, 
+                                wxStaticText* aUnitLabel, wxSpinButton* aSpinButton ) :
+    m_textCtrl( aTextInput ),
+    m_unitLabel( aUnitLabel ),
+    m_units( g_UserUnit ),
+    m_step( 1 ),
+    m_min( 0 ),
+    m_max( 1 )
 {
     // Use the currently selected units
-    m_units = g_UserUnit;
-    m_textCtrl = aTextInput;
     m_textCtrl->SetValue( wxT( "0" ) );
-    m_unitLabel = aUnitLabel;
     m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units ) );
 }
 
@@ -73,4 +77,4 @@ void WX_UNIT_BINDER::Enable( bool aEnable )
 {
     m_textCtrl->Enable( aEnable );
     m_unitLabel->Enable( aEnable );
-}
\ No newline at end of file
+}
diff --git eeschema/schedit.cpp eeschema/schedit.cpp
index 521cb18..c975808 100644
--- eeschema/schedit.cpp
+++ eeschema/schedit.cpp
@@ -459,6 +459,7 @@ void SCH_EDIT_FRAME::OnMoveItem( wxCommandEvent& aEvent )
         // Moving a marker has no sense
         wxFAIL_MSG( wxString::Format( wxT( "Cannot move item type %s" ),
                                       GetChars( item->GetClass() ) ) );
+        break;
     default:
         // Unknown items cannot be moved
         wxFAIL_MSG( wxString::Format(
diff --git pcbnew/dialogs/dialog_pns_length_tuning_settings.cpp pcbnew/dialogs/dialog_pns_length_tuning_settings.cpp
index b817a0b..dccb74e 100644
--- pcbnew/dialogs/dialog_pns_length_tuning_settings.cpp
+++ pcbnew/dialogs/dialog_pns_length_tuning_settings.cpp
@@ -99,7 +99,7 @@ void DIALOG_PNS_LENGTH_TUNING_SETTINGS::OnOkClick( wxCommandEvent& aEvent )
         m_settings.m_targetLength = m_targetLength.GetValue();
 
     if( m_settings.m_maxAmplitude < m_settings.m_minAmplitude )
-        m_settings.m_maxAmplitude = m_settings.m_maxAmplitude;
+        m_settings.m_maxAmplitude = m_settings.m_minAmplitude;
 
     m_settings.m_cornerType = m_miterStyle->GetSelection() ? PNS_MEANDER_SETTINGS::CHAMFER : PNS_MEANDER_SETTINGS::ROUND;
 

Follow ups