Fix a bug in ClassOf which crashes Pcbnew when its argument is NULL. It fixes bug #1329364.

This commit is contained in:
jean-pierre charras 2014-06-12 22:03:57 +02:00
parent bb79ec84bc
commit 52d2e7eb59
7 changed files with 12 additions and 8 deletions

View File

@ -150,7 +150,7 @@ struct remove_pointer<T*>
template <class T, class I> template <class T, class I>
bool IsA(const I *aObject) bool IsA(const I *aObject)
{ {
return remove_pointer<T>::type::ClassOf(aObject); return aObject && remove_pointer<T>::type::ClassOf(aObject);
} }
template <class T, class I> template <class T, class I>

View File

@ -222,7 +222,7 @@ private:
public: public:
static inline bool ClassOf( const EDA_ITEM* aItem ) static inline bool ClassOf( const EDA_ITEM* aItem )
{ {
return PCB_T == aItem->Type(); return aItem && PCB_T == aItem->Type();
} }
void SetFileName( const wxString& aFileName ) { m_fileName = aFileName; } void SetFileName( const wxString& aFileName ) { m_fileName = aFileName; }

View File

@ -60,6 +60,9 @@ public:
static inline bool ClassOf( const EDA_ITEM* aItem ) static inline bool ClassOf( const EDA_ITEM* aItem )
{ {
if( aItem == NULL )
return false;
switch( aItem->Type() ) switch( aItem->Type() )
{ {
case PCB_PAD_T: case PCB_PAD_T:

View File

@ -56,7 +56,7 @@ public:
static inline bool ClassOf( const EDA_ITEM* aItem ) static inline bool ClassOf( const EDA_ITEM* aItem )
{ {
return PCB_MODULE_EDGE_T == aItem->Type(); return aItem && PCB_MODULE_EDGE_T == aItem->Type();
} }
void Copy( EDGE_MODULE* source ); // copy structure void Copy( EDGE_MODULE* source ); // copy structure

View File

@ -68,7 +68,7 @@ public:
static inline bool ClassOf( const EDA_ITEM* aItem ) static inline bool ClassOf( const EDA_ITEM* aItem )
{ {
return PCB_MODULE_TEXT_T == aItem->Type(); return aItem && PCB_MODULE_TEXT_T == aItem->Type();
} }

View File

@ -82,7 +82,7 @@ class TRACK : public BOARD_CONNECTED_ITEM
public: public:
static inline bool ClassOf( const EDA_ITEM* aItem ) static inline bool ClassOf( const EDA_ITEM* aItem )
{ {
return PCB_TRACE_T == aItem->Type(); return aItem && PCB_TRACE_T == aItem->Type();
} }
BOARD_CONNECTED_ITEM* start; // pointers to a connected item (pad or track) BOARD_CONNECTED_ITEM* start; // pointers to a connected item (pad or track)
@ -382,7 +382,7 @@ public:
static inline bool ClassOf( const EDA_ITEM *aItem ) static inline bool ClassOf( const EDA_ITEM *aItem )
{ {
return PCB_VIA_T == aItem->Type(); return aItem && PCB_VIA_T == aItem->Type();
} }
// 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.

View File

@ -62,6 +62,7 @@ static void Abort_Create_Track( EDA_DRAW_PANEL* Panel, wxDC* DC )
{ {
PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Panel->GetParent(); PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Panel->GetParent();
BOARD* pcb = frame->GetBoard(); BOARD* pcb = frame->GetBoard();
TRACK* track = dyn_cast<TRACK*>( frame->GetCurItem() ); TRACK* track = dyn_cast<TRACK*>( frame->GetCurItem() );
if( track ) if( track )