[gnome-contacts/gnome-3-38] window: Add null-check for list_pane on startup



commit efabf4cdcc5693c05a9c04df23c73804fe4eadee
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sun Nov 15 15:14:29 2020 +0100

    window: Add null-check for list_pane on startup
    
    To implement search-as-you-type, we make sure to focus the search field
    if that wasn't the case already. However, if a user types something wile
    Contacts is still starting up, the UI hasn't finished by that time
    already, so that will lead us to dereferencing a NULL-pointer.
    
    To fix this nice and easy, let's to do a quick NULL-check before we try
    to focus anything.
    
    Fixes: https://gitlab.gnome.org/GNOME/gnome-contacts/-/issues/155
    (cherry picked from commit ee64d11e54caaa86477e8dad3ded08d1b8d9df84)

 src/contacts-window.vala | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/src/contacts-window.vala b/src/contacts-window.vala
index 53494562..4657c06a 100644
--- a/src/contacts-window.vala
+++ b/src/contacts-window.vala
@@ -433,7 +433,10 @@ public class Contacts.Window : Gtk.ApplicationWindow {
     } else if (((event.keyval == Gdk.Key.s) ||
                 (event.keyval == Gdk.Key.f)) &&
                ((event.state & Gdk.ModifierType.CONTROL_MASK) != 0)) {
-      Utils.grab_entry_focus_no_select (list_pane.filter_entry);
+      // Explicitly check if this.list_pane is already initialized,
+      // or we might crash at startup
+      if (this.list_pane != null && this.list_pane.filter_entry != null)
+          Utils.grab_entry_focus_no_select (this.list_pane.filter_entry);
     } else if (event.length >= 1 &&
                Gdk.keyval_to_unicode (event.keyval) != 0 &&
                (event.state & Gdk.ModifierType.CONTROL_MASK) == 0 &&
@@ -441,7 +444,10 @@ public class Contacts.Window : Gtk.ApplicationWindow {
                (event.keyval != Gdk.Key.Escape) &&
                (event.keyval != Gdk.Key.Tab) &&
                (event.keyval != Gdk.Key.BackSpace) ) {
-      Utils.grab_entry_focus_no_select (list_pane.filter_entry);
+      // Explicitly check if this.list_pane is already initialized,
+      // or we might crash at startup
+      if (this.list_pane != null && this.list_pane.filter_entry != null)
+          Utils.grab_entry_focus_no_select (this.list_pane.filter_entry);
       propagate_key_event (event);
     }
 


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