From 27f5257d49a05d4e43c77c44bdbcf2684e46162f Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Sun, 18 Jul 2010 18:40:48 +0200 Subject: [PATCH] GtkStyleContext: Don crash on empty class sets. --- gtk/gtkstylecontext.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c index 71f8c83a60..c1ec55dd7e 100644 --- a/gtk/gtkstylecontext.c +++ b/gtk/gtkstylecontext.c @@ -642,16 +642,21 @@ gtk_style_context_restore (GtkStyleContext *context) } static gboolean -style_class_find (GArray *array, - GQuark class_quark, - guint *position) +style_class_find (GArray *array, + GQuark class_quark, + guint *position) { guint min, max, mid; gboolean found = FALSE; + if (position) + *position = 0; + + if (!array || array->len == 0) + return FALSE; + min = 0; max = array->len - 1; - mid = max - min / 2; do { @@ -676,16 +681,21 @@ style_class_find (GArray *array, } static gboolean -child_style_class_find (GArray *array, - GQuark class_quark, - guint *position) +child_style_class_find (GArray *array, + GQuark class_quark, + guint *position) { guint min, max, mid; gboolean found = FALSE; + if (position) + *position = 0; + + if (!array || array->len == 0) + return FALSE; + min = 0; max = array->len - 1; - mid = max - min / 2; do {