Fix segfaults from not checking index

Return value of wxArrayString.Index() always needs to be check for
existence.
This commit is contained in:
Seth Hillbrand 2019-01-17 06:23:25 -08:00
parent 8b5127d9bc
commit c3a295df1a
2 changed files with 11 additions and 5 deletions

View File

@ -53,9 +53,10 @@ void GRID_CELL_ICON_TEXT_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, w
// draw the icon // draw the icon
// note that the set of icons might be smaller than the set of labels if the last // note that the set of icons might be smaller than the set of labels if the last
// label is <...>. // label is <...>.
if( m_names.Index( value ) < (int) m_icons.size() ) auto position = m_names.Index( value );
if( position < (int) m_icons.size() && position != wxNOT_FOUND )
{ {
bitmap = KiBitmap( (BITMAP_DEF) m_icons[ m_names.Index( value ) ] ); bitmap = KiBitmap( (BITMAP_DEF) m_icons[ position ] );
aDC.DrawBitmap( bitmap, rect.GetLeft() + 3, rect.GetTop() + 2, true ); aDC.DrawBitmap( bitmap, rect.GetLeft() + 3, rect.GetTop() + 2, true );
} }
// still need a bitmap to fetch the width // still need a bitmap to fetch the width

View File

@ -180,12 +180,17 @@ public:
pin->SetName( aValue ); pin->SetName( aValue );
break; break;
case COL_TYPE: case COL_TYPE:
if( g_typeNames.Index( aValue ) != wxNOT_FOUND )
pin->SetType( (ELECTRICAL_PINTYPE) g_typeNames.Index( aValue ), false ); pin->SetType( (ELECTRICAL_PINTYPE) g_typeNames.Index( aValue ), false );
break; break;
case COL_SHAPE: case COL_SHAPE:
if( g_shapeNames.Index( aValue ) != wxNOT_FOUND )
pin->SetShape( (GRAPHIC_PINSHAPE) g_shapeNames.Index( aValue ) ); pin->SetShape( (GRAPHIC_PINSHAPE) g_shapeNames.Index( aValue ) );
break; break;
case COL_ORIENTATION: case COL_ORIENTATION:
if( g_orientationNames.Index( aValue ) != wxNOT_FOUND )
pin->SetOrientation( LIB_PIN::GetOrientationCode( pin->SetOrientation( LIB_PIN::GetOrientationCode(
g_orientationNames.Index( aValue ) ), false ); g_orientationNames.Index( aValue ) ), false );
break; break;