[glib/glib-2-64: 1/2] gvariant: Ensure GVS.depth is initialised




commit 2b6d4081e2db0eb47549783d6f1f6d9e5bdda5d9
Author: Philip Withnall <withnall endlessm com>
Date:   Tue Aug 18 09:46:12 2020 +0100

    gvariant: Ensure GVS.depth is initialised
    
    When byteswapping the depth was accidentally left uninitialised.
    
    Coverity CID: #1430636
    Signed-off-by: Philip Withnall <withnall endlessm com>

 glib/gvariant-core.c | 15 +++++++++++++++
 glib/gvariant-core.h |  2 ++
 glib/gvariant.c      |  1 +
 3 files changed, 18 insertions(+)
---
diff --git a/glib/gvariant-core.c b/glib/gvariant-core.c
index f0b372f40..cff1b093c 100644
--- a/glib/gvariant-core.c
+++ b/glib/gvariant-core.c
@@ -666,6 +666,21 @@ g_variant_is_trusted (GVariant *value)
   return (value->state & STATE_TRUSTED) != 0;
 }
 
+/* < internal >
+ * g_variant_get_depth:
+ * @value: a #GVariant
+ *
+ * Gets the nesting depth of a #GVariant. This is 0 for a #GVariant with no
+ * children.
+ *
+ * Returns: nesting depth of @value
+ */
+gsize
+g_variant_get_depth (GVariant *value)
+{
+  return value->depth;
+}
+
 /* -- public -- */
 
 /**
diff --git a/glib/gvariant-core.h b/glib/gvariant-core.h
index fc19b7ec4..fc04711ac 100644
--- a/glib/gvariant-core.h
+++ b/glib/gvariant-core.h
@@ -34,4 +34,6 @@ gboolean                g_variant_is_trusted                            (GVarian
 
 GVariantTypeInfo *      g_variant_get_type_info                         (GVariant            *value);
 
+gsize                   g_variant_get_depth                             (GVariant            *value);
+
 #endif /* __G_VARIANT_CORE_H__ */
diff --git a/glib/gvariant.c b/glib/gvariant.c
index ee1a9c020..77d7e746b 100644
--- a/glib/gvariant.c
+++ b/glib/gvariant.c
@@ -5948,6 +5948,7 @@ g_variant_byteswap (GVariant *value)
       serialised.type_info = g_variant_get_type_info (trusted);
       serialised.size = g_variant_get_size (trusted);
       serialised.data = g_malloc (serialised.size);
+      serialised.depth = g_variant_get_depth (trusted);
       g_variant_store (trusted, serialised.data);
       g_variant_unref (trusted);
 


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