From 910dfbc0101e36fbe660db5f4342a1a488ae875d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Jan 2021 00:20:51 +0100 Subject: [PATCH] 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. --- src/gtk/choice.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/gtk/choice.cpp b/src/gtk/choice.cpp index 9c6ebc9039..ff0b6ea224 100644 --- a/src/gtk/choice.cpp +++ b/src/gtk/choice.cpp @@ -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