g_variant_get_child_value: Add a precondition on length
authorGiovanni Campagna <gcampagna@src.gnome.org>
Fri, 27 May 2011 20:03:04 +0000 (16:03 -0400)
committerColin Walters <walters@verbum.org>
Fri, 27 May 2011 20:05:56 +0000 (16:05 -0400)
Ensure callers get a warning if they pass a bad length.

Split into a separate commit and changed to order index before
n_children by Colin Walters <walters@verbum.org>

glib/gvariant-core.c

index 6b27266..d2bd576 100644 (file)
@@ -848,6 +848,8 @@ GVariant *
 g_variant_get_child_value (GVariant *value,
                            gsize     index_)
 {
+  g_return_val_if_fail (index_ < g_variant_n_children (value), NULL);
+
   if (~g_atomic_int_get (&value->state) & STATE_SERIALISED)
     {
       g_variant_lock (value);