eeschema: Check for proper type before dereference

When bundling a selection, we need to ensure that we have correct types
before attempting to dereference.

Fixes: lp:1841919
* https://bugs.launchpad.net/kicad/+bug/1841919
This commit is contained in:
Seth Hillbrand 2019-08-29 07:59:36 -07:00
parent c3274e15f2
commit 83b2332f1f
12 changed files with 85 additions and 4 deletions

View File

@ -78,6 +78,11 @@ public:
m_image->SetScale( aScale ); m_image->SetScale( aScale );
} }
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_BITMAP_T == aItem->Type();
}
wxString GetClass() const override wxString GetClass() const override
{ {
return wxT( "SCH_BITMAP" ); return wxT( "SCH_BITMAP" );

View File

@ -132,6 +132,11 @@ public:
~SCH_BUS_WIRE_ENTRY() { } ~SCH_BUS_WIRE_ENTRY() { }
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_BUS_WIRE_ENTRY_T == aItem->Type();
}
wxString GetClass() const override wxString GetClass() const override
{ {
return wxT( "SCH_BUS_WIRE_ENTRY" ); return wxT( "SCH_BUS_WIRE_ENTRY" );
@ -174,6 +179,11 @@ public:
~SCH_BUS_BUS_ENTRY() { } ~SCH_BUS_BUS_ENTRY() { }
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_BUS_BUS_ENTRY_T == aItem->Type();
}
wxString GetClass() const override wxString GetClass() const override
{ {
return wxT( "SCH_BUS_BUS_ENTRY" ); return wxT( "SCH_BUS_BUS_ENTRY" );

View File

@ -63,6 +63,11 @@ public:
~SCH_FIELD(); ~SCH_FIELD();
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_FIELD_T == aItem->Type();
}
wxString GetClass() const override wxString GetClass() const override
{ {
return wxT( "SCH_FIELD" ); return wxT( "SCH_FIELD" );

View File

@ -41,6 +41,11 @@ public:
~SCH_JUNCTION() { } ~SCH_JUNCTION() { }
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_JUNCTION_T == aItem->Type();
}
wxString GetClass() const override wxString GetClass() const override
{ {
return wxT( "SCH_JUNCTION" ); return wxT( "SCH_JUNCTION" );

View File

@ -57,6 +57,11 @@ public:
SCH_LINE* Next() const { return (SCH_LINE*) Pnext; } SCH_LINE* Next() const { return (SCH_LINE*) Pnext; }
SCH_LINE* Back() const { return (SCH_LINE*) Pback; } SCH_LINE* Back() const { return (SCH_LINE*) Pback; }
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_LINE_T == aItem->Type();
}
wxString GetClass() const override wxString GetClass() const override
{ {
return wxT( "SCH_LINE" ); return wxT( "SCH_LINE" );

View File

@ -38,6 +38,11 @@ public:
// Do not create a copy constructor. The one generated by the compiler is adequate. // Do not create a copy constructor. The one generated by the compiler is adequate.
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_MARKER_T == aItem->Type();
}
wxString GetClass() const override wxString GetClass() const override
{ {
return wxT( "SCH_MARKER" ); return wxT( "SCH_MARKER" );

View File

@ -46,6 +46,11 @@ public:
~SCH_NO_CONNECT() { } ~SCH_NO_CONNECT() { }
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_NO_CONNECT_T == aItem->Type();
}
wxString GetClass() const override wxString GetClass() const override
{ {
return wxT( "SCH_NO_CONNECT" ); return wxT( "SCH_NO_CONNECT" );

View File

@ -49,6 +49,11 @@ public:
SCH_PIN& operator=( const SCH_PIN& aPin ); SCH_PIN& operator=( const SCH_PIN& aPin );
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_PIN_T == aItem->Type();
}
wxString GetClass() const override wxString GetClass() const override
{ {
return wxT( "SCH_PIN" ); return wxT( "SCH_PIN" );

View File

@ -105,6 +105,11 @@ public:
DLIST< SCH_ITEM > & GetDrawList() { return m_drawList; } DLIST< SCH_ITEM > & GetDrawList() { return m_drawList; }
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_SCREEN_T == aItem->Type();
}
virtual wxString GetClass() const override virtual wxString GetClass() const override
{ {
return wxT( "SCH_SCREEN" ); return wxT( "SCH_SCREEN" );

View File

@ -91,6 +91,11 @@ public:
~SCH_SHEET_PIN() { } ~SCH_SHEET_PIN() { }
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_SHEET_PIN_T == aItem->Type();
}
wxString GetClass() const override wxString GetClass() const override
{ {
return wxT( "SCH_SHEET_PIN" ); return wxT( "SCH_SHEET_PIN" );
@ -243,6 +248,11 @@ public:
~SCH_SHEET(); ~SCH_SHEET();
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_SHEET_T == aItem->Type();
}
wxString GetClass() const override wxString GetClass() const override
{ {
return wxT( "SCH_SHEET" ); return wxT( "SCH_SHEET" );

View File

@ -93,6 +93,11 @@ public:
~SCH_TEXT() { } ~SCH_TEXT() { }
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_TEXT_T == aItem->Type();
}
virtual wxString GetClass() const override virtual wxString GetClass() const override
{ {
return wxT( "SCH_TEXT" ); return wxT( "SCH_TEXT" );
@ -217,6 +222,11 @@ public:
~SCH_LABEL() { } ~SCH_LABEL() { }
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_LABEL_T == aItem->Type();
}
wxString GetClass() const override wxString GetClass() const override
{ {
return wxT( "SCH_LABEL" ); return wxT( "SCH_LABEL" );
@ -258,6 +268,11 @@ public:
void Print( wxDC* DC, const wxPoint& offset ) override; void Print( wxDC* DC, const wxPoint& offset ) override;
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_GLOBAL_LABEL_T == aItem->Type();
}
wxString GetClass() const override wxString GetClass() const override
{ {
return wxT( "SCH_GLOBALLABEL" ); return wxT( "SCH_GLOBALLABEL" );
@ -303,6 +318,11 @@ public:
void Print( wxDC* DC, const wxPoint& offset ) override; void Print( wxDC* DC, const wxPoint& offset ) override;
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_HIER_LABEL_T == aItem->Type();
}
wxString GetClass() const override wxString GetClass() const override
{ {
return wxT( "SCH_HIERLABEL" ); return wxT( "SCH_HIERLABEL" );

View File

@ -696,12 +696,13 @@ bool EE_SELECTION_TOOL::selectMultiple()
view->Query( selectionBox, selectedItems ); // Get the list of selected items view->Query( selectionBox, selectedItems ); // Get the list of selected items
// Sheet pins aren't in the view; add them by hand // Sheet pins aren't in the view; add them by hand
for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems ) for( auto& pair : selectedItems )
{ {
if( static_cast<EDA_ITEM*>( pair.first )->Type() == SCH_SHEET_T ) auto item = dynamic_cast<EDA_ITEM*>( pair.first );
if( auto sheet = dyn_cast<SCH_SHEET*>( item ) )
{ {
SCH_SHEET* sheet = (SCH_SHEET*) pair.first; int layer = pair.second;
int layer = pair.second;
for( SCH_SHEET_PIN& pin : sheet->GetPins() ) for( SCH_SHEET_PIN& pin : sheet->GetPins() )
selectedItems.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( &pin, layer ) ); selectedItems.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( &pin, layer ) );