[gtk/bilelmoussaoui/entry-completion] entry completion: add checks that entry is set already




commit ce07505feb78b7c26b2e41e5a0d740409536cbf6
Author: Bilal Elmoussaoui <belmouss redhat com>
Date:   Tue Feb 8 10:51:38 2022 +0100

    entry completion: add checks that entry is set already
    
    If any of the APIs that assumes that the entry is set already is used
    before having one already set, things break pretty badly.
    
    Fixes a downstream issue reported at https://github.com/gtk-rs/gtk4-rs/issues/873

 gtk/gtkentrycompletion.c | 8 ++++++++
 1 file changed, 8 insertions(+)
---
diff --git a/gtk/gtkentrycompletion.c b/gtk/gtkentrycompletion.c
index 408047adf0..eda9f737b2 100644
--- a/gtk/gtkentrycompletion.c
+++ b/gtk/gtkentrycompletion.c
@@ -1211,6 +1211,8 @@ gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
                                      GtkTreeModel       *model,
                                      GtkTreeIter        *iter)
 {
+  g_return_val_if_fail (completion->entry != NULL, FALSE);
+
   char *str = NULL;
 
   gtk_tree_model_get (model, iter, completion->text_column, &str, -1);
@@ -1229,6 +1231,8 @@ gtk_entry_completion_cursor_on_match (GtkEntryCompletion *completion,
                                       GtkTreeModel       *model,
                                       GtkTreeIter        *iter)
 {
+  g_return_val_if_fail (completion->entry != NULL, FALSE);
+
   gtk_entry_completion_insert_completion (completion, model, iter);
 
   return TRUE;
@@ -1317,6 +1321,8 @@ static gboolean
 gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
                                          const char         *prefix)
 {
+  g_return_val_if_fail (completion->entry != NULL, FALSE);
+
   if (prefix)
     {
       int key_len;
@@ -1417,6 +1423,8 @@ gtk_entry_completion_insert_completion (GtkEntryCompletion *completion,
 void
 gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion)
 {
+  g_return_if_fail (completion->entry != NULL);
+
   gboolean done;
   char *prefix;
   GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (completion->entry));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]