Fix some Coverity issues.

This commit is contained in:
Wayne Stambaugh 2022-03-25 15:51:05 -04:00
parent edc7261099
commit 7da7864f5e
19 changed files with 65 additions and 14 deletions

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) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2022 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
@ -82,6 +82,7 @@ BOARD_ADAPTER::BOARD_ADAPTER() :
m_IsPreviewer( false ),
m_board( nullptr ),
m_3dModelManager( nullptr ),
m_renderSettings( nullptr ),
m_colors( nullptr ),
m_layerZcoordTop(),
m_layerZcoordBottom()

View File

@ -92,7 +92,8 @@ GR_TEXT_V_ALIGN_T EDA_TEXT::MapVertJustify( int aVertJustify )
EDA_TEXT::EDA_TEXT( const wxString& text ) :
m_text( text ),
m_bounding_box_cache_valid( false ),
m_bounding_box_cache_line( -1 )
m_bounding_box_cache_line( -1 ),
m_bounding_box_cache_inverted( false )
{
int sz = Mils2iu( DEFAULT_SIZE_TEXT );
SetTextSize( wxSize( sz, sz ) );
@ -122,6 +123,8 @@ EDA_TEXT::EDA_TEXT( const EDA_TEXT& aText )
m_bounding_box_cache_valid = aText.m_bounding_box_cache_valid;
m_bounding_box_cache = aText.m_bounding_box_cache;
m_bounding_box_cache_line = aText.m_bounding_box_cache_line;
m_bounding_box_cache_inverted = aText.m_bounding_box_cache_inverted;
}

View File

@ -198,7 +198,7 @@ void DIALOG_ERC::updateDisplayedCounts()
wxString msg;
if( m_ercRun )
if( m_ercRun && m_markerProvider && m_ignoredList )
{
msg.sprintf( m_violationsTitleTemplate, m_markerProvider->GetCount() );
m_notebook->SetPageText( 0, msg );

View File

@ -207,6 +207,8 @@ void LIB_PIN::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
LIB_SYMBOL* part = GetParent();
wxCHECK( part && opts, /* void */ );
/* Calculate pin orient taking in account the symbol orientation. */
int orient = PinDrawOrient( aTransform );

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2015-2021 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2015-2022 KiCad Developers, see change_log.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
@ -376,6 +376,11 @@ void SCH_BASE_FRAME::RefreshSelection()
void SCH_BASE_FRAME::AddToScreen( EDA_ITEM* aItem, SCH_SCREEN* aScreen )
{
// Null pointers will cause boost::ptr_vector to raise a boost::bad_pointer exception which
// will be unhandled. There is no valid reason to pass an invalid EDA_ITEM pointer to the
// screen append function.
wxCHECK( aItem != nullptr, /* voide */ );
auto screen = aScreen;
if( aScreen == nullptr )

View File

@ -1059,6 +1059,8 @@ void SCH_SEXPR_PLUGIN::saveText( SCH_TEXT* aText, int aNestLevel )
SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( aText );
wxCHECK( label, /* void */ );
m_out->Print( aNestLevel, "(%s %s",
getTextTypeToken( aText->Type() ),
m_out->Quotew( aText->GetText() ).c_str() );

View File

@ -1253,6 +1253,9 @@ int SCH_SHEET::ComparePageNum( const wxString& aPageNumberA, const wxString& aPa
// If not numeric, then sort as strings using natural sort
int result = StrNumCmp( aPageNumberA, aPageNumberB );
// Divide by zero bad.
wxCHECK( result != 0, 0 );
result = result / std::abs( result );
return result;

View File

@ -44,7 +44,7 @@ struct SYMBOL_INSTANCE_REFERENCE
// Things that can be annotated:
wxString m_Reference;
int m_Unit;
int m_Unit = 1;
// Things that can be back-annotated:
wxString m_Value;

View File

@ -1014,6 +1014,9 @@ bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer( std::shared_ptr<SYMBOL_BUFF
for( auto entry : derivedSymbols )
{
std::shared_ptr<SYMBOL_BUFFER> symbol = GetBuffer( entry );
wxCHECK2( symbol, continue );
LIB_SYMBOL* derivedSymbol = new LIB_SYMBOL( *symbol->GetSymbol() );
derivedSymbol->SetParent( parentSymbol );
result = aLibTable->SaveSymbol( m_libName, derivedSymbol );
@ -1165,6 +1168,9 @@ bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer( std::shared_ptr<SYMBOL_BUFF
for( auto entry : derivedSymbols )
{
std::shared_ptr<SYMBOL_BUFFER> symbol = GetBuffer( entry );
wxCHECK2( symbol, continue );
LIB_SYMBOL* derivedSymbol = new LIB_SYMBOL( *symbol->GetSymbol() );
derivedSymbol->SetParent( parentSymbol );

View File

@ -62,6 +62,7 @@ SYMBOL_LIB::SYMBOL_LIB( SCH_LIB_TYPE aType, const wxString& aFileName,
m_plugin.reset( SCH_IO_MGR::FindPlugin( m_pluginType ) );
m_properties = std::make_unique<PROPERTIES>();
m_mod_hash = 0;
}

View File

@ -287,6 +287,8 @@ bool SCH_EDIT_TOOL::Init()
{
const SCH_ITEM* schItem = dynamic_cast<const SCH_ITEM*>( item );
wxCHECK( schItem, false );
return ( schItem->HasLineStroke() && schItem->IsConnectable() )
|| item->Type() == SCH_JUNCTION_T;
} ) )
@ -1635,6 +1637,8 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
{
const SCH_ITEM* schItem = dynamic_cast<const SCH_ITEM*>( item );
wxCHECK( schItem, false );
return ( schItem->HasLineStroke() && schItem->IsConnectable() )
|| item->Type() == SCH_JUNCTION_T;
} ) )
@ -1728,6 +1732,8 @@ int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent )
default: UNIMPLEMENTED_FOR( wxString::Format( "%d.", convertTo ) ); break;
}
wxCHECK2( newtext, continue );
// Copy the old text item settings to the new one. Justifications are not copied
// because they are not used in labels. Justifications will be set to default value
// in the new text item type.

View File

@ -108,6 +108,8 @@ COMMIT& BOARD_COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO aModFlag
void BOARD_COMMIT::dirtyIntersectingZones( BOARD_ITEM* item )
{
wxCHECK( item, /* void */ );
if( item->Type() == PCB_FOOTPRINT_T )
{
static_cast<FOOTPRINT*>( item )->RunOnChildren(
@ -163,6 +165,8 @@ void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags )
std::vector<BOARD_ITEM*> bulkRemovedItems;
std::vector<BOARD_ITEM*> itemsChanged;
wxCHECK( frame, /* void */ );
if( Empty() )
return;

View File

@ -237,6 +237,8 @@ bool DRC_TEST_PROVIDER_DISALLOW::Run()
if( zone && zone->GetIsRuleArea() )
return true;
wxCHECK( pad, false );
item->ClearFlags( HOLE_PROXY ); // Just in case
checkDisallow( item );
@ -256,6 +258,7 @@ bool DRC_TEST_PROVIDER_DISALLOW::Run()
{
checkDisallow( item );
}
item->ClearFlags( HOLE_PROXY );
}
}

View File

@ -287,6 +287,8 @@ void DRC_TEST_PROVIDER_MISC::testTextVars()
BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item );
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( boardItem );
wxCHECK( boardItem, false );
if( text && text->GetShownText().Matches( wxT( "*${*}*" ) ) )
{
std::shared_ptr<DRC_ITEM>drcItem = DRC_ITEM::Create( DRCE_UNRESOLVED_VARIABLE );
@ -294,6 +296,7 @@ void DRC_TEST_PROVIDER_MISC::testTextVars()
reportViolation( drcItem, boardItem->GetPosition(), boardItem->GetLayer() );
}
return true;
} );

View File

@ -4,7 +4,7 @@
* Copyright (C) 2018 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2022 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
@ -441,8 +441,18 @@ void PCB_BASE_FRAME::FocusOnItem( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer )
while( !itemPoly.IsEmpty() )
{
focusPt = (wxPoint) itemPoly.BBox().Centre();
try
{
itemPoly.Deflate( step, 4, SHAPE_POLY_SET::CHAMFER_ACUTE_CORNERS );
}
catch( const ClipperLib::clipperException& exc )
{
// This may be overkill and could be an assertion but we are more likely to find
// any clipper errors this way.
wxLogError( wxT( "Clipper library exception '%s' occurred." ), exc.what() );
}
}
FocusOnLocation( focusPt );

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
* Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
* Copyright (C) 2012 KiCad Developers, see AUTHORS.TXT for contributors.
* Copyright (C) 2012, 2022 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
@ -44,7 +44,7 @@ enum LAYER_TYPE_T
struct TLAYER
{
PCB_LAYER_ID KiCadLayer;
LAYER_TYPE_T layerType;
LAYER_TYPE_T layerType = LAYER_TYPE_SIGNAL;
wxString netNameRef;
};

View File

@ -435,7 +435,8 @@ bool TEARDROP_MANAGER::ComputePointsOnPadVia( TEARDROP_PARAMETERS* aCurrParams,
}
else // Only PADS can have a not round shape
{
wxASSERT( pad );
wxCHECK( pad, false );
force_clip_shape = true;
preferred_height = aViaPad.m_Width * aCurrParams->m_HeightRatio;

View File

@ -1875,10 +1875,10 @@ void PCB_SELECTION_TOOL::FindItem( BOARD_ITEM* aItem )
//Let's refocus because there is an algortihm to avoid dialogs in there.
m_frame->FocusOnLocation( aItem->GetCenter() );
}
}
delete screenRect;
}
}
// Inform other potentially interested tools
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
}

View File

@ -2659,7 +2659,8 @@ void APPEARANCE_CONTROLS::onViewportChanged( wxCommandEvent& aEvent )
{
VIEWPORT* viewport = static_cast<VIEWPORT*>( m_cbViewports->GetClientData( index ) );
if( viewport )
wxCHECK( viewport, /* void */ );
doApplyViewport( *viewport );
if( !viewport->name.IsEmpty() )