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
// note that the set of icons might be smaller than the set of labels if the last
// 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 );
}
// still need a bitmap to fetch the width

View File

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