Assert in wxGTK wxChoice::GetString() if the index is invalid

Similar to the previous commit for wxMSW.

This commit is best viewed ignoring whitespace-only changes.
This commit is contained in:
Vadim Zeitlin 2021-01-17 00:20:51 +01:00
parent 98aaeadf54
commit 910dfbc010

View File

@ -278,21 +278,20 @@ wxString wxChoice::GetString(unsigned int n) const
{
wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid control") );
wxString str;
GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
GtkTreeModel *model = gtk_combo_box_get_model( combobox );
GtkTreeIter iter;
if (gtk_tree_model_iter_nth_child (model, &iter, NULL, n))
if (!gtk_tree_model_iter_nth_child (model, &iter, NULL, n))
{
GValue value = G_VALUE_INIT;
gtk_tree_model_get_value( model, &iter, m_stringCellIndex, &value );
wxString tmp = wxGTK_CONV_BACK( g_value_get_string( &value ) );
g_value_unset( &value );
return tmp;
wxFAIL_MSG( "invalid index" );
return wxString();
}
return str;
GValue value = G_VALUE_INIT;
gtk_tree_model_get_value( model, &iter, m_stringCellIndex, &value );
wxString tmp = wxGTK_CONV_BACK( g_value_get_string( &value ) );
g_value_unset( &value );
return tmp;
}
unsigned int wxChoice::GetCount() const