[gimp] app: fix GStrv argument validation in PDB calls.



commit 2d192ae80438566bc602eaecafea62952a764692
Author: Jehan <jehan girinstud io>
Date:   Tue May 24 19:48:36 2022 +0200

    app: fix GStrv argument validation in PDB calls.
    
    Bugs introduced in commit 8eb7f6df9e9:
    
    - The type test was wrong.
    - The UTF-8 validation test was also wrong since it was still working on
      a GimpArray even though the data was now a GStrv.
    
    Also I stop at the first invalid UTF-8 string element, otherwise later
    valid strings may hide previous invalid ones.
    
    This bug was mostly invisible since we don't have any core PDB API with
    GStrv parameter so far, only GStrv return value.

 app/pdb/gimpprocedure.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
---
diff --git a/app/pdb/gimpprocedure.c b/app/pdb/gimpprocedure.c
index eec37160d2..fd1b8954c8 100644
--- a/app/pdb/gimpprocedure.c
+++ b/app/pdb/gimpprocedure.c
@@ -986,7 +986,7 @@ gimp_procedure_validate_args (GimpProcedure  *procedure,
 
           /*  UTT-8 validate all strings  */
           if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_STRING ||
-              (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_BOXED &&
+              (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_BOXED &&
                G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_STRV))
             {
               gboolean valid = TRUE;
@@ -1000,16 +1000,18 @@ gimp_procedure_validate_args (GimpProcedure  *procedure,
                 }
               else
                 {
-                  const GimpArray *array = g_value_get_boxed (arg);
+                  const gchar **array = g_value_get_boxed (arg);
 
                   if (array)
                     {
-                      const gchar **strings = (const gchar **) array->data;
-                      gint          i;
-
-                      for (i = 0; i < array->length && valid; i++)
-                        if (strings[i])
-                          valid = g_utf8_validate (strings[i], -1, NULL);
+                      gint i;
+
+                      for (i = 0; array[i]; i++)
+                        {
+                          valid = g_utf8_validate (array[i], -1, NULL);
+                          if (! valid)
+                            break;
+                        }
                     }
                 }
 


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