[gimp/wip/nielsdg/string-array-to-strv: 2/2] libgimpbase: pass a NULL GStrv as an empty GStrv.




commit b41efbb671eda055f5276feb0c62d754b1ee3e81
Author: Jehan <jehan girinstud io>
Date:   Thu Feb 10 23:53:10 2022 +0100

    libgimpbase: pass a NULL GStrv as an empty GStrv.
    
    NULL is not a proper value for GStrv yet we cannot escape it in the PDB
    since we generate default values for non-passed arguments (especially in
    interactive case where most procedure arguments aren't set). And for
    such boxed type, it will be NULL.
    
    So when we see a NULL GStrv parameter, let's not ignore it (which will
    just crash the plug-in). Simply transform it to a GStrv of size 0.

 libgimpbase/gimpprotocol.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)
---
diff --git a/libgimpbase/gimpprotocol.c b/libgimpbase/gimpprotocol.c
index 176966d719..97b13b0fc4 100644
--- a/libgimpbase/gimpprotocol.c
+++ b/libgimpbase/gimpprotocol.c
@@ -1792,20 +1792,24 @@ _gp_params_write (GIOChannel *channel,
           break;
 
         case GP_PARAM_TYPE_STRV:
-          if (params[i].data.d_strv)
-            {
-              gint size = g_strv_length (params[i].data.d_strv);
-
-              if (! _gimp_wire_write_int32 (channel,
-                                            (guint32*) &size, 1,
-                                            user_data) ||
-                  ! _gimp_wire_write_string (channel,
-                                             params[i].data.d_strv,
-                                             size,
-                                             user_data))
-                return;
-              break;
-            }
+          {
+            gint size;
+
+            if (params[i].data.d_strv)
+              size = g_strv_length (params[i].data.d_strv);
+            else
+              size = 0;
+
+            if (! _gimp_wire_write_int32 (channel,
+                                          (guint32*) &size, 1,
+                                          user_data) ||
+                ! _gimp_wire_write_string (channel,
+                                           params[i].data.d_strv,
+                                           size,
+                                           user_data))
+              return;
+          }
+          break;
 
         case GP_PARAM_TYPE_ID_ARRAY:
           if (! _gimp_wire_write_string (channel,


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