From: Timm Bäder Date: Tue, 27 Aug 2019 08:05:51 +0000 (+0200) Subject: text: Fix a crash when retrieving the selected text X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~20^2~923 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=74208e9e0c8a4df42d88779c8a05b9313f119df5;p=gtk4.git text: Fix a crash when retrieving the selected text --- diff --git a/gtk/gtktext.c b/gtk/gtktext.c index 59281d5e99..5ac7637a98 100644 --- a/gtk/gtktext.c +++ b/gtk/gtktext.c @@ -2695,9 +2695,12 @@ _gtk_text_get_selected_text (GtkText *self) if (priv->selection_bound != priv->current_pos) { + const int start = MIN (priv->selection_bound, priv->current_pos); + const int end = MAX (priv->selection_bound, priv->current_pos); const char *text = gtk_entry_buffer_get_text (get_buffer (self)); - int start_index = g_utf8_offset_to_pointer (text, priv->selection_bound) - text; - int end_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text; + const int start_index = g_utf8_offset_to_pointer (text, start) - text; + const int end_index = g_utf8_offset_to_pointer (text, end) - text; + return g_strndup (text + start_index, end_index - start_index); }