Fix #10511 ScriptFu CRITICAL on scripts with no dialog, e.g. Reverse Layers

Magic number 1 changed to 2 in one place. Missed in earlier fix for #10127.

Changed magic number to a defined macro constant so it might not happen again,
should GimpConfig change again.
This commit is contained in:
bootchk
2023-12-22 09:33:18 -05:00
parent 60f8e47176
commit 11b7e4cded
3 changed files with 13 additions and 8 deletions

View File

@ -175,11 +175,8 @@ script_fu_run_procedure (GimpProcedure *procedure,
}
case GIMP_RUN_NONINTERACTIVE:
/* Verify actual args count equals declared arg count.
* Scripts declare args except run_mode (SF hides it.)
* pspecs have run_mode and one extra internal pspec, thus +2.
*/
if (n_pspecs != script->n_args + n_aux_args + 2)
/* Verify actual args count equals declared arg count. */
if (n_pspecs != script->n_args + n_aux_args + SF_ARG_TO_CONFIG_OFFSET)
status = GIMP_PDB_CALLING_ERROR;
if (status == GIMP_PDB_SUCCESS)

View File

@ -357,7 +357,7 @@ script_fu_script_get_command_from_params (SFScript *script,
for (i = 0; i < script->n_args; i++)
{
GValue value = G_VALUE_INIT;
GParamSpec *pspec = pspecs[i + 1];
GParamSpec *pspec = pspecs[i + SF_ARG_TO_CONFIG_OFFSET];
g_value_init (&value, pspec->value_type);
g_object_get_property (G_OBJECT (config), pspec->name, &value);
@ -495,10 +495,10 @@ script_fu_script_param_init (SFScript *script,
if (script->n_args > n &&
arg->type == type &&
/* The first pspec is "procedure", the second is "run-mode". */
n_pspecs > n + 2)
n_pspecs > n + SF_ARG_TO_CONFIG_OFFSET)
{
GValue value = G_VALUE_INIT;
GParamSpec *pspec = pspecs[n + 2];
GParamSpec *pspec = pspecs[n + SF_ARG_TO_CONFIG_OFFSET];
g_value_init (&value, pspec->value_type);
g_object_get_property (G_OBJECT (config), pspec->name, &value);

View File

@ -94,6 +94,14 @@ typedef struct
GType proc_class; /* GimpProcedure or GimpImageProcedure. */
} SFScript;
/* ScriptFu keeps array of SFArg, it's private arg specs.
* Scripts declare args except run_mode (SF hides it.)
* A GimpConfig has two extra leading properties, for procedure and run_mode.
* A set of GParamSpecs is derived from a config and also has two extra.
* This defines the difference in length between SF's arg spec array and a config.
*/
#define SF_ARG_TO_CONFIG_OFFSET 2
typedef struct
{
SFScript *script; /* script which defined this menu path and label */