[jsonrpc-glib] message: check for NULL before type checks



commit fb41c0046ba69b5938873e3087cfb376a9d724b5
Author: Christian Hergert <chergert redhat com>
Date:   Sat Jan 20 00:11:43 2018 -0800

    message: check for NULL before type checks

 src/jsonrpc-message.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
---
diff --git a/src/jsonrpc-message.c b/src/jsonrpc-message.c
index 1365d1f..5d3f0b1 100644
--- a/src/jsonrpc-message.c
+++ b/src/jsonrpc-message.c
@@ -360,18 +360,21 @@ jsonrpc_message_parse_object (GVariantDict *dict,
     {
       g_autoptr(GVariant) v = g_variant_dict_lookup_value (dict, key, NULL);
 
-      /* Safe to get data pointer because @v is a sub-variant of the
-       * larger buffer and therefore shares raw data */
-      if (g_variant_is_of_type (v, G_VARIANT_TYPE ("s")))
+      if (v != NULL)
         {
-          *((JsonrpcMessageGetString *)valptr)->valptr = g_variant_get_string (v, NULL);
-          ret = TRUE;
-        }
-      else if (g_variant_is_of_type (v, G_VARIANT_TYPE ("mv")) ||
-               g_variant_is_of_type (v, G_VARIANT_TYPE ("ms")))
-        {
-          *((JsonrpcMessageGetString *)valptr)->valptr = NULL;
-          ret = TRUE;
+          /* Safe to get data pointer because @v is a sub-variant of the
+           * larger buffer and therefore shares raw data */
+          if (g_variant_is_of_type (v, G_VARIANT_TYPE ("s")))
+            {
+              *((JsonrpcMessageGetString *)valptr)->valptr = g_variant_get_string (v, NULL);
+              ret = TRUE;
+            }
+          else if (g_variant_is_of_type (v, G_VARIANT_TYPE ("mv")) ||
+                   g_variant_is_of_type (v, G_VARIANT_TYPE ("ms")))
+            {
+              *((JsonrpcMessageGetString *)valptr)->valptr = NULL;
+              ret = TRUE;
+            }
         }
     }
   else if (IS_GET_INT32 (valptr))


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