From 3807b2f3116f754ef442d1eae9515bea9a884c6f Mon Sep 17 00:00:00 2001 From: Bruno Lopes Date: Tue, 31 Mar 2026 16:58:26 -0300 Subject: [PATCH] app, plug-ins: More sscanf_s on Windows --- app/core/gimpgradient-load.c | 14 +++++++++++--- app/operations/gimplevelsconfig.c | 9 +++++++++ plug-ins/common/compose.c | 12 ++++++++++++ .../fractal-explorer/fractal-explorer-dialogs.c | 4 ++++ plug-ins/gfig/gfig-style.c | 12 ++++++++++++ plug-ins/gfig/gfig.c | 12 ++++++++++++ 6 files changed, 60 insertions(+), 3 deletions(-) diff --git a/app/core/gimpgradient-load.c b/app/core/gimpgradient-load.c index d43edf1304..a0d92b5947 100644 --- a/app/core/gimpgradient-load.c +++ b/app/core/gimpgradient-load.c @@ -135,6 +135,7 @@ gimp_gradient_load (GimpContext *context, gint right_color_type; gdouble left_rgba[4]; gdouble right_rgba[4]; + gint n_matched; seg = gimp_gradient_segment_new (); @@ -175,9 +176,16 @@ gimp_gradient_load (GimpContext *context, gegl_color_set_pixel (seg->left_color, babl_format ("R'G'B'A double"), left_rgba); gegl_color_set_pixel (seg->right_color, babl_format ("R'G'B'A double"), right_rgba); - switch (sscanf (end, "%d %d %d %d", - &type, &color, - &left_color_type, &right_color_type)) +#ifndef _UCRT + n_matched = sscanf (end, "%d %d %d %d", + &type, &color, + &left_color_type, &right_color_type); +#else + n_matched = sscanf_s (end, "%d %d %d %d", + &type, &color, + &left_color_type, &right_color_type); +#endif + switch (n_matched) { case 4: seg->left_color_type = (GimpGradientColor) left_color_type; diff --git a/app/operations/gimplevelsconfig.c b/app/operations/gimplevelsconfig.c index d1783d2091..d0b0045090 100644 --- a/app/operations/gimplevelsconfig.c +++ b/app/operations/gimplevelsconfig.c @@ -904,12 +904,21 @@ gimp_levels_config_load_cruft (GimpLevelsConfig *config, return FALSE; } +#ifndef _UCRT fields = sscanf (line, "%d %d %d %d %31s", &low_input[i], &high_input[i], &low_output[i], &high_output[i], float_buf); +#else + fields = sscanf_s (line, "%d %d %d %d %31s", + &low_input[i], + &high_input[i], + &low_output[i], + &high_output[i], + float_buf, (unsigned) sizeof (float_buf)); +#endif g_free (line); diff --git a/plug-ins/common/compose.c b/plug-ins/common/compose.c index 14b083265e..a15e1af661 100644 --- a/plug-ins/common/compose.c +++ b/plug-ins/common/compose.c @@ -620,6 +620,7 @@ compose_run (GimpProcedure *procedure, parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size); parasite_data = g_strndup (parasite_data, parasite_size); +#ifndef _UCRT nret = sscanf (parasite_data, "source=%d type=%31s %d %d %d %d", &source, @@ -628,6 +629,17 @@ compose_run (GimpProcedure *procedure, input + 1, input + 2, input + 3); +#else + nret = sscanf_s (parasite_data, + "source=%d type=%31s %d %d %d %d", + &source, + composevals.compose_type, + (unsigned int) sizeof (composevals.compose_type), + input, + input + 1, + input + 2, + input + 3); +#endif gimp_parasite_free (parasite); g_free (parasite_data); diff --git a/plug-ins/fractal-explorer/fractal-explorer-dialogs.c b/plug-ins/fractal-explorer/fractal-explorer-dialogs.c index eb833efeff..f194a25a5e 100644 --- a/plug-ins/fractal-explorer/fractal-explorer-dialogs.c +++ b/plug-ins/fractal-explorer/fractal-explorer-dialogs.c @@ -1659,7 +1659,11 @@ load_options (fractalexplorerOBJ *xxx, while (!feof (fp) && strcmp (load_buf, "")) { /* Get option name */ +#ifndef _UCRT sscanf (load_buf, "%255s %255s", str_buf, opt_buf); +#else + sscanf_s (load_buf, "%255s %255s", str_buf, (unsigned)_countof(str_buf), opt_buf, (unsigned)_countof(opt_buf)); +#endif if (!strcmp (str_buf, "fractaltype:")) { diff --git a/plug-ins/gfig/gfig-style.c b/plug-ins/gfig/gfig-style.c index 55121d9e08..6f1c20b459 100644 --- a/plug-ins/gfig/gfig-style.c +++ b/plug-ins/gfig/gfig-style.c @@ -202,8 +202,16 @@ gfig_read_parameter_gimp_rgb (gchar **text, ptr++; if (!strcmp (tmpstr, name)) { +#ifndef _UCRT sscanf (ptr, fmt_str, colorstr_r, colorstr_g, colorstr_b, colorstr_a); +#else + sscanf_s (ptr, fmt_str, + colorstr_r, (unsigned int)sizeof(colorstr_r), + colorstr_g, (unsigned int)sizeof(colorstr_g), + colorstr_b, (unsigned int)sizeof(colorstr_b), + colorstr_a, (unsigned int)sizeof(colorstr_a)); +#endif gegl_color_set_rgba_with_space (*style_entry, g_ascii_strtod (colorstr_r, &endptr), g_ascii_strtod (colorstr_g, &endptr), @@ -237,7 +245,11 @@ gfig_load_style (Style *style, get_line (load_buf2, MAX_LOAD_LINE, fp, 0); /* nuke final > and preserve spaces in name */ +#ifndef _UCRT if (1 != sscanf (load_buf2, "