[gimp] libgimp: fix writing empty array GValues in gimp_value_to_gp_param()



commit 97bbd4773ef872085a7d900fbec5ff09bf703ce2
Author: Michael Natterer <mitch gimp org>
Date:   Mon Jan 6 16:16:18 2020 +0100

    libgimp: fix writing empty array GValues in gimp_value_to_gp_param()
    
    When g_value_get_boxed() returns a NULL array, we would encode
    nonsense on the wire and run into warnings. Now we simply send a
    zero-length array.

 libgimp/gimpgpparams-body.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/libgimp/gimpgpparams-body.c b/libgimp/gimpgpparams-body.c
index 6ce274695c..71468c5522 100644
--- a/libgimp/gimpgpparams-body.c
+++ b/libgimp/gimpgpparams-body.c
@@ -785,10 +785,10 @@ gimp_value_to_gp_param (const GValue *value,
     {
       GimpArray *array = g_value_get_boxed (value);
 
+      param->param_type = GP_PARAM_TYPE_ARRAY;
+
       if (array)
         {
-          param->param_type = GP_PARAM_TYPE_ARRAY;
-
           param->data.d_array.size = array->length;
 
           if (full_copy)
@@ -799,6 +799,7 @@ gimp_value_to_gp_param (const GValue *value,
         }
       else
         {
+          param->data.d_array.size = 0;
           param->data.d_array.data = NULL;
         }
     }
@@ -806,10 +807,10 @@ gimp_value_to_gp_param (const GValue *value,
     {
       GimpStringArray *array = g_value_get_boxed (value);
 
+      param->param_type = GP_PARAM_TYPE_STRING_ARRAY;
+
       if (array)
         {
-          param->param_type = GP_PARAM_TYPE_STRING_ARRAY;
-
           param->data.d_string_array.size = array->length;
 
           if (full_copy)
@@ -821,6 +822,7 @@ gimp_value_to_gp_param (const GValue *value,
         }
       else
         {
+          param->data.d_string_array.size = 0,
           param->data.d_string_array.data = NULL;
         }
     }
@@ -828,12 +830,12 @@ gimp_value_to_gp_param (const GValue *value,
     {
       GimpObjectArray *array = g_value_get_boxed (value);
 
+      param->param_type = GP_PARAM_TYPE_ID_ARRAY;
+
       if (array)
         {
           gint i;
 
-          param->param_type = GP_PARAM_TYPE_ID_ARRAY;
-
           if (full_copy)
             param->data.d_id_array.type_name =
               g_strdup (g_type_name (array->object_type));
@@ -871,6 +873,7 @@ gimp_value_to_gp_param (const GValue *value,
         }
       else
         {
+          param->data.d_id_array.size = 0;
           param->data.d_id_array.data = NULL;
         }
     }


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