[libadwaita/wip/exalm/leaflet-fix] leaflet: Null check visible child in find_swipeable_page()




commit 1526d9ddebcea7e98c15f2862d1c5f63db10516b
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Jun 18 14:53:42 2021 +0500

    leaflet: Null check visible child in find_swipeable_page()
    
    See https://gitlab.gnome.org/GNOME/libhandy/-/merge_requests/774

 src/adw-leaflet.c    | 4 ++++
 tests/test-leaflet.c | 6 ++++++
 2 files changed, 10 insertions(+)
---
diff --git a/src/adw-leaflet.c b/src/adw-leaflet.c
index 78ca8634..e925e5ba 100644
--- a/src/adw-leaflet.c
+++ b/src/adw-leaflet.c
@@ -481,6 +481,10 @@ find_swipeable_page (AdwLeaflet             *self,
   GList *l;
 
   l = g_list_find (self->children, self->visible_child);
+
+  if (!l)
+    return NULL;
+
   do {
     l = (direction == ADW_NAVIGATION_DIRECTION_BACK) ? l->prev : l->next;
 
diff --git a/tests/test-leaflet.c b/tests/test-leaflet.c
index 1ef56fb9..44f60071 100644
--- a/tests/test-leaflet.c
+++ b/tests/test-leaflet.c
@@ -80,6 +80,12 @@ test_adw_leaflet_navigate (void)
   leaflet = ADW_LEAFLET (adw_leaflet_new ());
   g_assert_nonnull (leaflet);
 
+  result = adw_leaflet_navigate (leaflet, ADW_NAVIGATION_DIRECTION_BACK);
+  g_assert_false (result);
+
+  result = adw_leaflet_navigate (leaflet, ADW_NAVIGATION_DIRECTION_FORWARD);
+  g_assert_false (result);
+
   for (i = 0; i < 3; i++) {
     AdwLeafletPage *page;
 


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