From e6297121977cf9aac79b4210f6cae93bd50d58fc Mon Sep 17 00:00:00 2001 From: wwp Date: Wed, 8 Jun 2016 14:44:25 +0300 Subject: [PATCH] Ticket #3562: fix Glib-critical asserts in empty WListbox. Signed-off-by: Andrew Borodin --- lib/widget/listbox.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c index 6e89300a7..ca593413b 100644 --- a/lib/widget/listbox.c +++ b/lib/widget/listbox.c @@ -52,7 +52,7 @@ const global_keymap_t *listbox_map = NULL; /*** file scope macro definitions ****************************************************************/ /* Gives the position of the last item. */ -#define LISTBOX_LAST(l) (g_queue_is_empty ((l)->list) ? 0 : (int) g_queue_get_length ((l)->list) - 1) +#define LISTBOX_LAST(l) (listbox_is_empty (l) ? 0 : (int) g_queue_get_length ((l)->list) - 1) /*** file scope type declarations ****************************************************************/ @@ -231,10 +231,13 @@ listbox_y_pos (WListbox * l, int y) static void listbox_fwd (WListbox * l, gboolean wrap) { - if ((guint) l->pos + 1 < g_queue_get_length (l->list)) - listbox_select_entry (l, l->pos + 1); - else if (wrap) - listbox_select_first (l); + if (!listbox_is_empty (l)) + { + if ((guint) l->pos + 1 < g_queue_get_length (l->list)) + listbox_select_entry (l, l->pos + 1); + else if (wrap) + listbox_select_first (l); + } } /* --------------------------------------------------------------------------------------------- */ @@ -250,10 +253,13 @@ listbox_fwd_n (WListbox * l, int n) static void listbox_back (WListbox * l, gboolean wrap) { - if (l->pos > 0) - listbox_select_entry (l, l->pos - 1); - else if (wrap) - listbox_select_last (l); + if (!listbox_is_empty (l)) + { + if (l->pos > 0) + listbox_select_entry (l, l->pos - 1); + else if (wrap) + listbox_select_last (l); + } } /* --------------------------------------------------------------------------------------------- */ @@ -402,6 +408,9 @@ listbox_do_action (WListbox * l) { int action; + if (listbox_is_empty (l)) + return; + if (l->callback != NULL) action = l->callback (l); else -- 2.11.4.GIT