Commit 52d2e7eb authored by jean-pierre charras's avatar jean-pierre charras

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

parent bb79ec84
......@@ -150,11 +150,11 @@ struct remove_pointer<T*>
template <class T, class I>
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>
bool IsA(const I& aObject)
bool IsA(const I& aObject)
{
return remove_pointer<T>::type::ClassOf(&aObject);
}
......
......@@ -222,7 +222,7 @@ private:
public:
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; }
......
......@@ -60,9 +60,12 @@ public:
static inline bool ClassOf( const EDA_ITEM* aItem )
{
if( aItem == NULL )
return false;
switch( aItem->Type() )
{
case PCB_PAD_T:
case PCB_PAD_T:
case PCB_TRACE_T:
case PCB_VIA_T:
case PCB_ZONE_AREA_T:
......
......@@ -56,7 +56,7 @@ public:
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
......
......@@ -68,7 +68,7 @@ public:
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return PCB_MODULE_TEXT_T == aItem->Type();
return aItem && PCB_MODULE_TEXT_T == aItem->Type();
}
......
......@@ -82,7 +82,7 @@ class TRACK : public BOARD_CONNECTED_ITEM
public:
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)
......@@ -382,7 +382,7 @@ public:
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.
......
......@@ -62,6 +62,7 @@ static void Abort_Create_Track( EDA_DRAW_PANEL* Panel, wxDC* DC )
{
PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Panel->GetParent();
BOARD* pcb = frame->GetBoard();
TRACK* track = dyn_cast<TRACK*>( frame->GetCurItem() );
if( track )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment