Coverity warning fixes.

This commit is contained in:
Wayne Stambaugh 2023-10-27 16:48:03 -04:00
parent 8b3ac31646
commit 6269453416
9 changed files with 92 additions and 20 deletions

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
@ -121,7 +122,20 @@ TOOL_EVENT TOOL_ACTION::MakeEvent() const
evt = TOOL_EVENT( TC_COMMAND, TA_ACTION, m_name, m_scope );
if( m_group.has_value() )
evt.SetActionGroup( m_group.value() );
{
// This should probably be checking to see if the m_group option is actually
// set rather than attempting to access the value when no option is set. If
// that is the case, then the check above should first check if the options is
// set so that an exception cannot be thrown.
try
{
evt.SetActionGroup( m_group.value() );
}
catch( const std::bad_optional_access& e )
{
wxFAIL_MSG( e.what() );
}
}
if( m_param.has_value() )
evt.SetParameter( m_param );

View File

@ -157,8 +157,19 @@ const std::string TOOL_EVENT::Format() const
if( m_actionGroup.has_value() )
{
ev += m_actionGroup.value().GetName()
+ "(" + std::to_string( m_actionGroup.value().GetGroupID() ) + ")" + " ";
// This should probably be checking to see if the m_actionGroup option is
// actually set rather than attempting to access the value when no option
// is set. If that is the case, then the check above should first check
// if the options is set so that an exception cannot be thrown.
try
{
ev += m_actionGroup.value().GetName() +
"(" + std::to_string( m_actionGroup.value().GetGroupID() ) + ")" + " ";
}
catch( const std::bad_optional_access& e )
{
wxFAIL_MSG( e.what() );
}
}
else
{

View File

@ -4,7 +4,7 @@
* Copyright (C) 1992-2018 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2010 Lorenzo Marcantonio
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -103,6 +103,7 @@ struct SCH_PLOT_SETTINGS
m_useBackgroundColor( true ),
m_HPGLPenSize( 1.0 ),
m_HPGLPaperSizeSelect( HPGL_PAGE_SIZE::DEFAULT ),
m_PDFPropertyPopups( false ),
m_theme(),
m_outputDirectory(),
m_outputFile(),
@ -219,4 +220,4 @@ private:
wxString m_lastOutputFilePath;
};
#endif
#endif

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 CERN
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -454,11 +454,22 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
grid->SetSnap( !evt->Modifier( MD_SHIFT ) );
grid->SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
if( grid )
{
grid->SetSnap( !evt->Modifier( MD_SHIFT ) );
grid->SetUseGrid( getView()->GetGAL()->GetGridSnapping() &&
!evt->DisableGridSnapping() );
cursorPos = grid->Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_GRAPHICS );
controls->ForceCursorPosition( true, cursorPos );
cursorPos = grid->Align( controls->GetMousePosition(),
GRID_HELPER_GRIDS::GRID_GRAPHICS );
controls->ForceCursorPosition( true, cursorPos );
}
else
{
// This check is based on the assumption that the grid object must be valid.
// If this assumption is wrong, please fix the code above.
wxCHECK( false, 0 );
}
if( !m_editPoints || evt->IsSelectionEvent() )
break;

View File

@ -391,7 +391,17 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
bool SCH_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COMMIT* aCommit, bool aIsSlice )
{
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
EESCHEMA_SETTINGS* cfg = nullptr;
try
{
cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
}
catch( const std::runtime_error& e )
{
wxCHECK_MSG( false, false, e.what() );
}
KIGFX::VIEW_CONTROLS* controls = getViewControls();
EE_GRID_HELPER grid( m_toolMgr );
bool wasDragging = m_moveInProgress && m_isDrag;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2015-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -59,6 +59,29 @@ struct CAMERA_FRUSTUM
SFVEC3F fbr; ///< Far Bottom Right
float nearD, farD, ratio, angle, tang;
float nw, nh, fw, fh;
CAMERA_FRUSTUM() :
nc( { 0.0, 0.0, 0.0 } ),
fc( { 0.0, 0.0, 0.0 } ),
ntl( { 0.0, 0.0, 0.0 } ),
ntr( { 0.0, 0.0, 0.0 } ),
nbl( { 0.0, 0.0, 0.0 } ),
nbr( { 0.0, 0.0, 0.0 } ),
ftl( { 0.0, 0.0, 0.0 } ),
ftr( { 0.0, 0.0, 0.0 } ),
fbl( { 0.0, 0.0, 0.0 } ),
fbr( { 0.0, 0.0, 0.0 } ),
nearD( 0.0 ),
farD( 0.0 ),
ratio( 1.0 ),
angle( 0.0 ),
tang( 0.0 ),
nw( 0.0 ),
nh( 0.0 ),
fw( 0.0 ),
fh( 0.0 )
{
}
};

View File

@ -864,11 +864,11 @@ bool PANEL_FP_LIB_TABLE::convertLibrary( STRING_UTF8_MAP* aOldFileProps,
wxArrayString fpNames;
wxFileName newFileName( aNewFilePath );
if( !newFileName.DirExists() && !wxMkDir( aNewFilePath, wxS_DIR_DEFAULT ) )
return false;
try
{
if( !newFileName.DirExists() )
wxMkDir( aNewFilePath, wxS_DIR_DEFAULT );
bool bestEfforts = false; // throw on first error
oldFilePI->FootprintEnumerate( fpNames, aOldFilePath, bestEfforts, aOldFileProps );

View File

@ -222,6 +222,8 @@ bool ITEM::collideSimple( const ITEM* aHead, const NODE* aNode,
obs.m_head = const_cast<ITEM*>( aHead );
obs.m_item = const_cast<ITEM*>( this );
obs.m_clearance = clearance;
obs.m_distFirst = 0;
obs.m_maxFanoutWidth = 0;
aCtx->obstacles.insert( obs );
}
else

View File

@ -128,15 +128,15 @@ NODE::~NODE()
int NODE::GetClearance( const ITEM* aA, const ITEM* aB, bool aUseClearanceEpsilon ) const
{
if( !m_ruleResolver )
if( !m_ruleResolver )
return 100000;
if( aA->IsVirtual() || aB->IsVirtual() )
return 0;
if( aA->IsVirtual() || aB->IsVirtual() )
return 0;
int cl = m_ruleResolver->Clearance( aA, aB, aUseClearanceEpsilon );
return cl;
return cl;
}
@ -973,7 +973,7 @@ void NODE::followLine( LINKED_ITEM* aCurrent, bool aScanDirection, int& aPos, in
const VECTOR2I p = aCurrent->Anchor( aScanDirection ^ prevReversed );
const JOINT* jt = FindJoint( p, aCurrent );
assert( jt );
wxCHECK( jt, /* void */ );
aCorners[aPos] = jt->Pos();
aSegments[aPos] = aCurrent;