From ea5824ebd7a7f363171bc3c1fcbfef473f7928fa Mon Sep 17 00:00:00 2001 From: Jehan Date: Mon, 28 Oct 2024 10:46:17 +0100 Subject: [PATCH] app, libgimp, pdb: fix other int sizes. Avoid the stack smashing bug from yesterday in other functions. Additionally to fixing other functions, do not cast the pointer to size in the PDB generation scripts so that we can quickly spot such bugs in the future, through compilation time warnings, instead of hiding them. --- app/pdb/context-cmds.c | 2 +- app/pdb/drawable-color-cmds.c | 8 ++++---- app/pdb/gradient-cmds.c | 4 ++-- app/pdb/image-select-cmds.c | 2 +- app/pdb/paint-tools-cmds.c | 34 ++++++++++++++++----------------- app/pdb/path-cmds.c | 2 +- app/pdb/plug-in-compat-cmds.c | 4 ++-- libgimp/gimpcontext_pdb.c | 2 +- libgimp/gimpdrawablecolor_pdb.c | 4 ++-- libgimp/gimpdrawablecolor_pdb.h | 4 ++-- libgimp/gimpgradient_pdb.c | 6 +++--- libgimp/gimpgradient_pdb.h | 2 +- libgimp/gimppath_pdb.c | 6 +++--- pdb/groups/drawable_color.pdb | 4 ++-- pdb/groups/gradient.pdb | 2 +- pdb/pdb.pl | 8 ++++---- 16 files changed, 47 insertions(+), 47 deletions(-) diff --git a/app/pdb/context-cmds.c b/app/pdb/context-cmds.c index ca68be1124..cfb85acfec 100644 --- a/app/pdb/context-cmds.c +++ b/app/pdb/context-cmds.c @@ -781,7 +781,7 @@ context_set_line_dash_pattern_invoker (GimpProcedure *procedure, gsize num_dashes; const gdouble *dashes; - dashes = gimp_value_get_float_array (gimp_value_array_index (args, 0), (gsize *) &num_dashes); + dashes = gimp_value_get_float_array (gimp_value_array_index (args, 0), &num_dashes); if (success) { diff --git a/app/pdb/drawable-color-cmds.c b/app/pdb/drawable-color-cmds.c index ebe52004c2..d81c1a467d 100644 --- a/app/pdb/drawable-color-cmds.c +++ b/app/pdb/drawable-color-cmds.c @@ -207,12 +207,12 @@ drawable_curves_explicit_invoker (GimpProcedure *procedure, gboolean success = TRUE; GimpDrawable *drawable; gint channel; - gint num_values; + gsize num_values; const gdouble *values; drawable = g_value_get_object (gimp_value_array_index (args, 0)); channel = g_value_get_enum (gimp_value_array_index (args, 1)); - values = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_values); + values = gimp_value_get_float_array (gimp_value_array_index (args, 2), &num_values); if (success) { @@ -255,12 +255,12 @@ drawable_curves_spline_invoker (GimpProcedure *procedure, gboolean success = TRUE; GimpDrawable *drawable; gint channel; - gint num_points; + gsize num_points; const gdouble *points; drawable = g_value_get_object (gimp_value_array_index (args, 0)); channel = g_value_get_enum (gimp_value_array_index (args, 1)); - points = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_points); + points = gimp_value_get_float_array (gimp_value_array_index (args, 2), &num_points); if (success) { diff --git a/app/pdb/gradient-cmds.c b/app/pdb/gradient-cmds.c index b1c3aaa604..a7309ccf1d 100644 --- a/app/pdb/gradient-cmds.c +++ b/app/pdb/gradient-cmds.c @@ -225,14 +225,14 @@ gradient_get_custom_samples_invoker (GimpProcedure *procedure, gboolean success = TRUE; GimpValueArray *return_vals; GimpGradient *gradient; - gint num_samples; + gsize num_samples; const gdouble *positions; gboolean reverse; gsize num_color_samples = 0; gdouble *color_samples = NULL; gradient = g_value_get_object (gimp_value_array_index (args, 0)); - positions = gimp_value_get_float_array (gimp_value_array_index (args, 1), (gsize *) &num_samples); + positions = gimp_value_get_float_array (gimp_value_array_index (args, 1), &num_samples); reverse = g_value_get_boolean (gimp_value_array_index (args, 2)); if (success) diff --git a/app/pdb/image-select-cmds.c b/app/pdb/image-select-cmds.c index 988d86db41..0e3e55c731 100644 --- a/app/pdb/image-select-cmds.c +++ b/app/pdb/image-select-cmds.c @@ -295,7 +295,7 @@ image_select_polygon_invoker (GimpProcedure *procedure, image = g_value_get_object (gimp_value_array_index (args, 0)); operation = g_value_get_enum (gimp_value_array_index (args, 1)); - segs = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_segs); + segs = gimp_value_get_float_array (gimp_value_array_index (args, 2), &num_segs); if (success) { diff --git a/app/pdb/paint-tools-cmds.c b/app/pdb/paint-tools-cmds.c index 914fdfc103..b24c463d6f 100644 --- a/app/pdb/paint-tools-cmds.c +++ b/app/pdb/paint-tools-cmds.c @@ -118,7 +118,7 @@ airbrush_invoker (GimpProcedure *procedure, drawable = g_value_get_object (gimp_value_array_index (args, 0)); pressure = g_value_get_double (gimp_value_array_index (args, 1)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), &num_strokes); if (success) { @@ -164,7 +164,7 @@ airbrush_default_invoker (GimpProcedure *procedure, const gdouble *strokes; drawable = g_value_get_object (gimp_value_array_index (args, 0)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), &num_strokes); if (success) { @@ -214,7 +214,7 @@ clone_invoker (GimpProcedure *procedure, clone_type = g_value_get_enum (gimp_value_array_index (args, 2)); src_x = g_value_get_double (gimp_value_array_index (args, 3)); src_y = g_value_get_double (gimp_value_array_index (args, 4)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 5), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 5), &num_strokes); if (success) { @@ -267,7 +267,7 @@ clone_default_invoker (GimpProcedure *procedure, const gdouble *strokes; drawable = g_value_get_object (gimp_value_array_index (args, 0)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), &num_strokes); if (success) { @@ -313,7 +313,7 @@ convolve_invoker (GimpProcedure *procedure, drawable = g_value_get_object (gimp_value_array_index (args, 0)); pressure = g_value_get_double (gimp_value_array_index (args, 1)); convolve_type = g_value_get_enum (gimp_value_array_index (args, 2)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 3), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 3), &num_strokes); if (success) { @@ -360,7 +360,7 @@ convolve_default_invoker (GimpProcedure *procedure, const gdouble *strokes; drawable = g_value_get_object (gimp_value_array_index (args, 0)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), &num_strokes); if (success) { @@ -408,7 +408,7 @@ dodgeburn_invoker (GimpProcedure *procedure, exposure = g_value_get_double (gimp_value_array_index (args, 1)); dodgeburn_type = g_value_get_enum (gimp_value_array_index (args, 2)); dodgeburn_mode = g_value_get_enum (gimp_value_array_index (args, 3)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 4), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 4), &num_strokes); if (success) { @@ -456,7 +456,7 @@ dodgeburn_default_invoker (GimpProcedure *procedure, const gdouble *strokes; drawable = g_value_get_object (gimp_value_array_index (args, 0)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), &num_strokes); if (success) { @@ -500,7 +500,7 @@ eraser_invoker (GimpProcedure *procedure, gint method; drawable = g_value_get_object (gimp_value_array_index (args, 0)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), &num_strokes); hardness = g_value_get_enum (gimp_value_array_index (args, 2)); method = g_value_get_enum (gimp_value_array_index (args, 3)); @@ -549,7 +549,7 @@ eraser_default_invoker (GimpProcedure *procedure, const gdouble *strokes; drawable = g_value_get_object (gimp_value_array_index (args, 0)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), &num_strokes); if (success) { @@ -597,7 +597,7 @@ heal_invoker (GimpProcedure *procedure, src_drawable = g_value_get_object (gimp_value_array_index (args, 1)); src_x = g_value_get_double (gimp_value_array_index (args, 2)); src_y = g_value_get_double (gimp_value_array_index (args, 3)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 4), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 4), &num_strokes); if (success) { @@ -649,7 +649,7 @@ heal_default_invoker (GimpProcedure *procedure, const gdouble *strokes; drawable = g_value_get_object (gimp_value_array_index (args, 0)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), &num_strokes); if (success) { @@ -695,7 +695,7 @@ paintbrush_invoker (GimpProcedure *procedure, drawable = g_value_get_object (gimp_value_array_index (args, 0)); fade_out = g_value_get_double (gimp_value_array_index (args, 1)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), &num_strokes); method = g_value_get_enum (gimp_value_array_index (args, 3)); gradient_length = g_value_get_double (gimp_value_array_index (args, 4)); @@ -775,7 +775,7 @@ paintbrush_default_invoker (GimpProcedure *procedure, const gdouble *strokes; drawable = g_value_get_object (gimp_value_array_index (args, 0)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), &num_strokes); if (success) { @@ -817,7 +817,7 @@ pencil_invoker (GimpProcedure *procedure, const gdouble *strokes; drawable = g_value_get_object (gimp_value_array_index (args, 0)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), &num_strokes); if (success) { @@ -861,7 +861,7 @@ smudge_invoker (GimpProcedure *procedure, drawable = g_value_get_object (gimp_value_array_index (args, 0)); pressure = g_value_get_double (gimp_value_array_index (args, 1)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 2), &num_strokes); if (success) { @@ -907,7 +907,7 @@ smudge_default_invoker (GimpProcedure *procedure, const gdouble *strokes; drawable = g_value_get_object (gimp_value_array_index (args, 0)); - strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), (gsize *) &num_strokes); + strokes = gimp_value_get_float_array (gimp_value_array_index (args, 1), &num_strokes); if (success) { diff --git a/app/pdb/path-cmds.c b/app/pdb/path-cmds.c index e7d232d54d..a569748563 100644 --- a/app/pdb/path-cmds.c +++ b/app/pdb/path-cmds.c @@ -730,7 +730,7 @@ path_stroke_new_from_points_invoker (GimpProcedure *procedure, path = g_value_get_object (gimp_value_array_index (args, 0)); type = g_value_get_enum (gimp_value_array_index (args, 1)); - controlpoints = gimp_value_get_float_array (gimp_value_array_index (args, 2), (gsize *) &num_points); + controlpoints = gimp_value_get_float_array (gimp_value_array_index (args, 2), &num_points); closed = g_value_get_boolean (gimp_value_array_index (args, 3)); if (success) diff --git a/app/pdb/plug-in-compat-cmds.c b/app/pdb/plug-in-compat-cmds.c index f0df820944..676047d827 100644 --- a/app/pdb/plug-in-compat-cmds.c +++ b/app/pdb/plug-in-compat-cmds.c @@ -1138,11 +1138,11 @@ plug_in_convmatrix_invoker (GimpProcedure *procedure, gint bmode; drawable = g_value_get_object (gimp_value_array_index (args, 2)); - matrix = gimp_value_get_float_array (gimp_value_array_index (args, 3), (gsize *) &argc_matrix); + matrix = gimp_value_get_float_array (gimp_value_array_index (args, 3), &argc_matrix); alpha_alg = g_value_get_boolean (gimp_value_array_index (args, 4)); divisor = g_value_get_double (gimp_value_array_index (args, 5)); offset = g_value_get_double (gimp_value_array_index (args, 6)); - channels = gimp_value_get_int32_array (gimp_value_array_index (args, 7), (gsize *) &argc_channels); + channels = gimp_value_get_int32_array (gimp_value_array_index (args, 7), &argc_channels); bmode = g_value_get_int (gimp_value_array_index (args, 8)); if (success) diff --git a/libgimp/gimpcontext_pdb.c b/libgimp/gimpcontext_pdb.c index 3de6c86b01..51f26f877e 100644 --- a/libgimp/gimpcontext_pdb.c +++ b/libgimp/gimpcontext_pdb.c @@ -1159,7 +1159,7 @@ gimp_context_get_line_dash_pattern (gsize *num_dashes, if (success) { - *dashes = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 1, (gsize *) num_dashes); + *dashes = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 1, num_dashes); } gimp_value_array_unref (return_vals); diff --git a/libgimp/gimpdrawablecolor_pdb.c b/libgimp/gimpdrawablecolor_pdb.c index 5aeb3bc9d3..8171bd1a26 100644 --- a/libgimp/gimpdrawablecolor_pdb.c +++ b/libgimp/gimpdrawablecolor_pdb.c @@ -207,7 +207,7 @@ gimp_drawable_colorize_hsl (GimpDrawable *drawable, gboolean gimp_drawable_curves_explicit (GimpDrawable *drawable, GimpHistogramChannel channel, - gint num_values, + gsize num_values, const gdouble *values) { GimpValueArray *args; @@ -260,7 +260,7 @@ gimp_drawable_curves_explicit (GimpDrawable *drawable, gboolean gimp_drawable_curves_spline (GimpDrawable *drawable, GimpHistogramChannel channel, - gint num_points, + gsize num_points, const gdouble *points) { GimpValueArray *args; diff --git a/libgimp/gimpdrawablecolor_pdb.h b/libgimp/gimpdrawablecolor_pdb.h index 4c9147a7ea..d4fb5e9737 100644 --- a/libgimp/gimpdrawablecolor_pdb.h +++ b/libgimp/gimpdrawablecolor_pdb.h @@ -47,11 +47,11 @@ gboolean gimp_drawable_colorize_hsl (GimpDrawable *drawable, gdouble lightness); gboolean gimp_drawable_curves_explicit (GimpDrawable *drawable, GimpHistogramChannel channel, - gint num_values, + gsize num_values, const gdouble *values); gboolean gimp_drawable_curves_spline (GimpDrawable *drawable, GimpHistogramChannel channel, - gint num_points, + gsize num_points, const gdouble *points); gboolean gimp_drawable_extract_component (GimpDrawable *drawable, gint component, diff --git a/libgimp/gimpgradient_pdb.c b/libgimp/gimpgradient_pdb.c index 4c93cc94d3..9502572fec 100644 --- a/libgimp/gimpgradient_pdb.c +++ b/libgimp/gimpgradient_pdb.c @@ -195,7 +195,7 @@ gimp_gradient_get_uniform_samples (GimpGradient *gradient, if (success) { - *color_samples = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 1, (gsize *) num_color_samples); + *color_samples = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 1, num_color_samples); } gimp_value_array_unref (return_vals); @@ -225,7 +225,7 @@ gimp_gradient_get_uniform_samples (GimpGradient *gradient, **/ gboolean gimp_gradient_get_custom_samples (GimpGradient *gradient, - gint num_samples, + gsize num_samples, const gdouble *positions, gboolean reverse, gsize *num_color_samples, @@ -256,7 +256,7 @@ gimp_gradient_get_custom_samples (GimpGradient *gradient, if (success) { - *color_samples = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 1, (gsize *) num_color_samples); + *color_samples = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 1, num_color_samples); } gimp_value_array_unref (return_vals); diff --git a/libgimp/gimpgradient_pdb.h b/libgimp/gimpgradient_pdb.h index b0a53ddc0d..0b9cea2ff4 100644 --- a/libgimp/gimpgradient_pdb.h +++ b/libgimp/gimpgradient_pdb.h @@ -41,7 +41,7 @@ gboolean gimp_gradient_get_uniform_samples (GimpGradient gsize *num_color_samples, gdouble **color_samples); gboolean gimp_gradient_get_custom_samples (GimpGradient *gradient, - gint num_samples, + gsize num_samples, const gdouble *positions, gboolean reverse, gsize *num_color_samples, diff --git a/libgimp/gimppath_pdb.c b/libgimp/gimppath_pdb.c index bfa3fde788..bbc1f5871f 100644 --- a/libgimp/gimppath_pdb.c +++ b/libgimp/gimppath_pdb.c @@ -191,7 +191,7 @@ gimp_path_get_strokes (GimpPath *path, if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) { - stroke_ids = GIMP_VALUES_DUP_INT32_ARRAY (return_vals, 1, (gsize *) num_strokes); + stroke_ids = GIMP_VALUES_DUP_INT32_ARRAY (return_vals, 1, num_strokes); } gimp_value_array_unref (return_vals); @@ -701,7 +701,7 @@ gimp_path_stroke_get_points (GimpPath *path, if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) { type = GIMP_VALUES_GET_ENUM (return_vals, 1); - *controlpoints = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 2, (gsize *) num_points); + *controlpoints = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 2, num_points); *closed = GIMP_VALUES_GET_BOOLEAN (return_vals, 3); } @@ -808,7 +808,7 @@ gimp_path_stroke_interpolate (GimpPath *path, if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) { - coords = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 1, (gsize *) num_coords); + coords = GIMP_VALUES_DUP_FLOAT_ARRAY (return_vals, 1, num_coords); *closed = GIMP_VALUES_GET_BOOLEAN (return_vals, 2); } diff --git a/pdb/groups/drawable_color.pdb b/pdb/groups/drawable_color.pdb index 9b73e792f9..5c626292fe 100644 --- a/pdb/groups/drawable_color.pdb +++ b/pdb/groups/drawable_color.pdb @@ -199,7 +199,7 @@ HELP desc => 'The channel to modify' }, { name => 'values', type => 'floatarray', desc => 'The explicit curve', - array => { name => 'num_values', type => '256 <= int32 <= 2096', + array => { name => 'num_values', type => '256 <= size <= 2096', desc => 'The number of values in the new curve' } } ); @@ -257,7 +257,7 @@ HELP { name => 'points', type => 'floatarray', desc => 'The spline control points: { cp1.x, cp1.y, cp2.x, cp2.y, ... }', - array => { name => 'num_points', type => '4 <= int32 <= 2048', + array => { name => 'num_points', type => '4 <= size <= 2048', desc => 'The number of values in the control point array' } } ); diff --git a/pdb/groups/gradient.pdb b/pdb/groups/gradient.pdb index 784e285e6b..22f589bec0 100644 --- a/pdb/groups/gradient.pdb +++ b/pdb/groups/gradient.pdb @@ -219,7 +219,7 @@ HELP ${gradient_arg_spec}, { name => 'positions', type => 'floatarray', desc => 'The list of positions to sample along the gradient', - array => { name => 'num_samples', type => '1 <= int32', + array => { name => 'num_samples', type => '1 <= size', desc => 'The number of samples to take' } }, { name => 'reverse', type => 'boolean', desc => 'Use the reverse gradient' } diff --git a/pdb/pdb.pl b/pdb/pdb.pl index d7ea8512e1..5e7239a94c 100644 --- a/pdb/pdb.pl +++ b/pdb/pdb.pl @@ -89,8 +89,8 @@ package Gimp::CodeGen::pdb; init_value => 'NULL', in_annotate => '(element-type gint32)', out_annotate => '(element-type gint32) (transfer full)', - get_value_func => '$var = gimp_value_get_int32_array ($value, (gsize *) &$var_len)', - dup_value_func => '$var = GIMP_VALUES_DUP_INT32_ARRAY ($value, (gsize *) $var_len)', + get_value_func => '$var = gimp_value_get_int32_array ($value, &$var_len)', + dup_value_func => '$var = GIMP_VALUES_DUP_INT32_ARRAY ($value, $var_len)', set_value_func => 'gimp_value_set_int32_array ($value, $var, $var_len)', take_value_func => 'gimp_value_take_int32_array ($value, $var, $var_len)' }, @@ -102,8 +102,8 @@ package Gimp::CodeGen::pdb; init_value => 'NULL', in_annotate => '(element-type gdouble)', out_annotate => '(element-type gdouble) (transfer full)', - get_value_func => '$var = gimp_value_get_float_array ($value, (gsize *) &$var_len)', - dup_value_func => '$var = GIMP_VALUES_DUP_FLOAT_ARRAY ($value, (gsize *) $var_len)', + get_value_func => '$var = gimp_value_get_float_array ($value, &$var_len)', + dup_value_func => '$var = GIMP_VALUES_DUP_FLOAT_ARRAY ($value, $var_len)', set_value_func => 'gimp_value_set_float_array ($value, $var, $var_len)', take_value_func => 'gimp_value_take_float_array ($value, $var, $var_len)' },