Coverity and compiler warning fixes

* Initialize variables
* Test dynamic casts

Fixes https://gitlab.com/kicad/code/kicad/issues/4620
This commit is contained in:
Ian McInerney 2020-06-05 12:49:32 +01:00
parent 1c46bf1955
commit 4357c1d3b3
10 changed files with 67 additions and 37 deletions

View File

@ -86,15 +86,27 @@ END_EVENT_TABLE()
EDA_3D_CANVAS::EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList, BOARD* aBoard,
BOARD_ADAPTER& aBoardAdapter, CCAMERA& aCamera,
S3D_CACHE* a3DCachePointer ) :
HIDPI_GL_CANVAS( aParent, wxID_ANY, aAttribList, wxDefaultPosition, wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE ),
m_eventDispatcher( nullptr ),
m_parentStatusBar( nullptr ),
m_glRC( nullptr ),
m_boardAdapter( aBoardAdapter ),
m_camera( aCamera ),
m_3d_render( nullptr )
S3D_CACHE* a3DCachePointer )
: HIDPI_GL_CANVAS( aParent, wxID_ANY, aAttribList, wxDefaultPosition, wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE ),
m_eventDispatcher( nullptr ),
m_parentStatusBar( nullptr ),
m_parentInfoBar( nullptr ),
m_glRC( nullptr ),
m_is_opengl_initialized( false ),
m_mouse_is_moving( false ),
m_mouse_was_moved( false ),
m_camera_is_moving( false ),
m_render_pivot( false ),
m_camera_moving_speed( 1.0f ),
m_strtime_camera_movement( 0 ),
m_animation_enabled( true ),
m_moving_speed_multiplier( 3 ),
m_boardAdapter( aBoardAdapter ),
m_camera( aCamera ),
m_3d_render( nullptr ),
m_opengl_supports_raytracing( false ),
m_render_raytracing_was_requested( false )
{
wxLogTrace( m_logTrace, "EDA_3D_CANVAS::EDA_3D_CANVAS" );
@ -112,21 +124,6 @@ EDA_3D_CANVAS::EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList, BOARD*
NULL,
this );
m_mouse_was_moved = false;
m_mouse_is_moving = false;
m_camera_is_moving = false;
m_render_pivot = false;
m_camera_moving_speed = 1.0f;
m_animation_enabled = true;
m_moving_speed_multiplier = 3;
m_strtime_camera_movement = 0;
m_is_opengl_initialized = false;
m_render_raytracing_was_requested = false;
m_opengl_supports_raytracing = false;
m_3d_render_raytracing = new C3D_RENDER_RAYTRACING( m_boardAdapter, m_camera );
m_3d_render_ogl_legacy = new C3D_RENDER_OGL_LEGACY( m_boardAdapter, m_camera );

View File

@ -31,8 +31,10 @@ using KIGFX::COLOR4D;
const int viewer3dSchemaVersion = 0;
EDA_3D_VIEWER_SETTINGS::EDA_3D_VIEWER_SETTINGS() :
APP_SETTINGS_BASE( "3d_viewer", viewer3dSchemaVersion ), m_Render()
EDA_3D_VIEWER_SETTINGS::EDA_3D_VIEWER_SETTINGS()
: APP_SETTINGS_BASE( "3d_viewer", viewer3dSchemaVersion ),
m_Render(),
m_Camera()
{
m_params.emplace_back( new PARAM<int>( "render.engine", &m_Render.engine,
static_cast<int>( RENDER_ENGINE::OPENGL_LEGACY ),

View File

@ -279,7 +279,7 @@ void PANEL_COLOR_SETTINGS::updateColor( int aLayer, const KIGFX::COLOR4D& aColor
m_swatches[aLayer]->SetSwatchColor( aColor, false );
if( aLayer == m_backgroundLayer )
if( m_currentSettings && aLayer == m_backgroundLayer )
{
COLOR4D background = m_currentSettings->GetColor( m_backgroundLayer );

View File

@ -404,8 +404,8 @@ void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent )
keyEvent.m_shiftDown = ( acceleratorKey->GetFlags() & wxMOD_SHIFT ) > 0;
keyEvent.m_altDown = ( acceleratorKey->GetFlags() & wxMOD_ALT ) > 0;
if( dynamic_cast<wxTextEntry*>( focus ) )
TEXTENTRY_TRICKS::OnCharHook( dynamic_cast<wxTextEntry*>( focus ), keyEvent );
if( auto ctrl = dynamic_cast<wxTextEntry*>( focus ) )
TEXTENTRY_TRICKS::OnCharHook( ctrl, keyEvent );
else
focus->HandleWindowEvent( keyEvent );

View File

@ -163,8 +163,9 @@ DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, wxWindow* aPa
// Restore last zoom. (If auto-zooming we'll adjust when we load the footprint.)
CVPCB_SETTINGS* cfg = dynamic_cast<CVPCB_SETTINGS*>( config() );
wxASSERT( cfg );
GetCanvas()->GetView()->SetScale( cfg->m_FootprintViewerZoom );
if( cfg )
GetCanvas()->GetView()->SetScale( cfg->m_FootprintViewerZoom );
updateView();
@ -524,7 +525,7 @@ BOARD_ITEM_CONTAINER* DISPLAY_FOOTPRINTS_FRAME::GetModel() const
void DISPLAY_FOOTPRINTS_FRAME::SetAutoZoom( bool aAutoZoom )
{
CVPCB_SETTINGS* cfg = dynamic_cast<CVPCB_SETTINGS*>( config() );
wxASSERT( cfg );
wxCHECK( cfg, /* void */ );
cfg->m_FootprintViewerAutoZoom = aAutoZoom;
}
@ -532,6 +533,6 @@ void DISPLAY_FOOTPRINTS_FRAME::SetAutoZoom( bool aAutoZoom )
bool DISPLAY_FOOTPRINTS_FRAME::GetAutoZoom()
{
CVPCB_SETTINGS* cfg = dynamic_cast<CVPCB_SETTINGS*>( config() );
wxASSERT( cfg );
wxCHECK( cfg, false );
return cfg->m_FootprintViewerAutoZoom;
}

View File

@ -976,7 +976,8 @@ int SCH_EDITOR_CONTROL::UpdateNetHighlighting( const TOOL_EVENT& aEvent )
redraw |= item->IsBrightened();
if( item->Type() == SCH_COMPONENT_T )
// comp is only non-null if the item is a SCH_COMPONENT_T
if( comp )
{
redraw |= comp->HasBrightenedPins();

View File

@ -293,7 +293,11 @@ private:
public:
INFOBAR_REPORTER( WX_INFOBAR* aInfoBar )
: REPORTER(), m_messageSet( false ), m_infoBar( aInfoBar )
: REPORTER(),
m_messageSet( false ),
m_infoBar( aInfoBar ),
m_message( wxEmptyString ),
m_severity( RPT_SEVERITY_UNDEFINED )
{
}

View File

@ -479,6 +479,7 @@ APOLYGON6::APOLYGON6( ALTIUM_PARSER& aReader )
ARULE6::ARULE6( ALTIUM_PARSER& aReader )
{
// Initalize all variables and make Coverity happy
clearanceGap = 0;
planeclearanceClearance = 0;
polygonconnectAirgapwidth = 0;
polygonconnectReliefconductorwidth = 0;

View File

@ -452,7 +452,7 @@ void GERBER_JOBFILE_WRITER::addJSONDesignRules()
bool hasInnerLayers = m_pcb->GetCopperLayerCount() > 2;
// Search a smaller clearance in other net classes, if any.
for( const std::pair<wxString, NETCLASSPTR>& entry : dsnSettings.m_NetClasses )
for( const std::pair<const wxString, NETCLASSPTR>& entry : dsnSettings.m_NetClasses )
minclearanceOuter = std::min( minclearanceOuter, entry.second->GetClearance() );
// job file knows different clearance types.

View File

@ -45,8 +45,32 @@ const int pcbnewSchemaVersion = 0;
PCBNEW_SETTINGS::PCBNEW_SETTINGS()
: APP_SETTINGS_BASE( "pcbnew", pcbnewSchemaVersion ),
m_AuiPanels(),
m_Cleanup(),
m_DrcDialog(),
m_ExportIdf(),
m_ExportStep(),
m_ExportSvg(),
m_ExportVrml(),
m_FootprintWizardList(),
m_GenDrill(),
m_ImportGraphics(),
m_NetlistDialog(),
m_PlaceFile(),
m_Plot(),
m_FootprintChooser(),
m_UserGrid(),
m_Zones(),
m_FootprintViewer(),
m_FootprintWizard(),
m_Display(),
m_FastGrid1( 0 ),
m_FastGrid2( 0 ),
m_Use45DegreeGraphicSegments( false ),
m_FlipLeftRight( false ),
m_PolarCoords( false ),
m_RotationAngle( 900 ),
m_PlotLineWidth( 0.1 ),
m_ShowPageLimits( true ),
m_PnsSettings( nullptr ),
m_FootprintViewerAutoZoom( false ),