From 84c7274c70a39944add610b94181fcab6f267824 Mon Sep 17 00:00:00 2001 From: Bruno Lopes Date: Tue, 31 Mar 2026 10:32:50 -0300 Subject: [PATCH] plug-ins: Use fscanf_s on Windows to fix CRT_INSECURE_DEPRECATE warnings --- plug-ins/common/sphere-designer.c | 4 +++ plug-ins/gradient-flare/gradient-flare.c | 20 ++++++++++++++ plug-ins/lighting/lighting-ui.c | 33 ++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/plug-ins/common/sphere-designer.c b/plug-ins/common/sphere-designer.c index a54a25a81a..2dd488230f 100644 --- a/plug-ins/common/sphere-designer.c +++ b/plug-ins/common/sphere-designer.c @@ -2091,7 +2091,11 @@ loadit (const gchar * fn) return; } +#ifndef _UCRT if (2 != fscanf (f, "%d %d", &majtype, &type) || majtype < 0 || majtype > 2) +#else + if (2 != fscanf_s (f, "%d %d", &majtype, &type) || majtype < 0 || majtype > 2) +#endif { g_message (_("File '%s' is not a valid save file."), gimp_filename_to_utf8 (fn)); diff --git a/plug-ins/gradient-flare/gradient-flare.c b/plug-ins/gradient-flare/gradient-flare.c index ce5c2c8d61..72083dff84 100644 --- a/plug-ins/gradient-flare/gradient-flare.c +++ b/plug-ins/gradient-flare/gradient-flare.c @@ -1441,7 +1441,11 @@ gflare_read_int (gint *intvar, if (gf->error) return; +#ifndef _UCRT if (fscanf (gf->fp, "%d", intvar) != 1) +#else + if (fscanf_s (gf->fp, "%d", intvar) != 1) +#endif gf->error = TRUE; } @@ -1454,7 +1458,11 @@ gflare_read_double (gdouble *dblvar, if (gf->error) return; +#ifndef _UCRT if (fscanf (gf->fp, "%30s", buf) == 1) +#else + if (fscanf_s (gf->fp, "%30s", buf, (unsigned int)sizeof(buf)) == 1) +#endif *dblvar = g_ascii_strtod (buf, NULL); else gf->error = TRUE; @@ -1471,7 +1479,11 @@ gflare_read_gradient_name (GradientName name, /* FIXME: this is buggy */ +#ifndef _UCRT if (fscanf (gf->fp, "%1023s", tmp) == 1) +#else + if (fscanf_s (gf->fp, "%1023s", tmp, (unsigned int)sizeof(tmp)) == 1) +#endif { /* @GRADIENT_NAME */ gradient_name_decode (dec, tmp); @@ -1491,7 +1503,11 @@ gflare_read_shape (GFlareShape *shape, if (gf->error) return; +#ifndef _UCRT if (fscanf (gf->fp, "%1023s", tmp) == 1) +#else + if (fscanf_s (gf->fp, "%1023s", tmp, (unsigned int)sizeof(tmp)) == 1) +#endif { for (i = 0; i < GF_NUM_SHAPES; i++) if (strcmp (tmp, gflare_shapes[i]) == 0) @@ -1513,7 +1529,11 @@ gflare_read_mode (GFlareMode *mode, if (gf->error) return; +#ifndef _UCRT if (fscanf (gf->fp, "%1023s", tmp) == 1) +#else + if (fscanf_s (gf->fp, "%1023s", tmp, (unsigned int)sizeof(tmp)) == 1) +#endif { for (i = 0; i < GF_NUM_MODES; i++) if (strcmp (tmp, gflare_modes[i]) == 0) diff --git a/plug-ins/lighting/lighting-ui.c b/plug-ins/lighting/lighting-ui.c index 91d50e6d54..c198815ffc 100644 --- a/plug-ins/lighting/lighting-ui.c +++ b/plug-ins/lighting/lighting-ui.c @@ -954,7 +954,11 @@ load_preset_response (GtkFileChooser *chooser, } else { +#ifndef _UCRT fscanf (fp, "Number of lights: %d", &num_lights); +#else + fscanf_s (fp, "Number of lights: %d", &num_lights); +#endif /* initialize lights to off */ for (k = 0; k < NUM_LIGHTS; k++) @@ -964,7 +968,11 @@ load_preset_response (GtkFileChooser *chooser, { source = &mapvals.lightsource[k]; +#ifndef _UCRT fscanf (fp, " Type: %20s", type_label); +#else + fscanf_s (fp, " Type: %20s", type_label, (unsigned int)sizeof(type_label)); +#endif if (!strcmp (type_label, "Point")) source->type = POINT_LIGHT; @@ -984,7 +992,14 @@ load_preset_response (GtkFileChooser *chooser, sizeof (buffer1) - 1, sizeof (buffer2) - 1, sizeof (buffer3) - 1); +#ifndef _UCRT fscanf (fp, fmt_str, buffer1, buffer2, buffer3); +#else + fscanf_s (fp, fmt_str, + buffer1, (unsigned int)sizeof(buffer1), + buffer2, (unsigned int)sizeof(buffer2), + buffer3, (unsigned int)sizeof(buffer3)); +#endif source->position.x = g_ascii_strtod (buffer1, &endptr); source->position.y = g_ascii_strtod (buffer2, &endptr); source->position.z = g_ascii_strtod (buffer3, &endptr); @@ -994,7 +1009,14 @@ load_preset_response (GtkFileChooser *chooser, sizeof (buffer1) - 1, sizeof (buffer2) - 1, sizeof (buffer3) - 1); +#ifndef _UCRT fscanf (fp, fmt_str, buffer1, buffer2, buffer3); +#else + fscanf_s (fp, fmt_str, + buffer1, (unsigned int)sizeof(buffer1), + buffer2, (unsigned int)sizeof(buffer2), + buffer3, (unsigned int)sizeof(buffer3)); +#endif source->direction.x = g_ascii_strtod (buffer1, &endptr); source->direction.y = g_ascii_strtod (buffer2, &endptr); source->direction.z = g_ascii_strtod (buffer3, &endptr); @@ -1004,7 +1026,14 @@ load_preset_response (GtkFileChooser *chooser, sizeof (buffer1) - 1, sizeof (buffer2) - 1, sizeof (buffer3) - 1); +#ifndef _UCRT fscanf (fp, fmt_str, buffer1, buffer2, buffer3); +#else + fscanf_s (fp, fmt_str, + buffer1, (unsigned int)sizeof(buffer1), + buffer2, (unsigned int)sizeof(buffer2), + buffer3, (unsigned int)sizeof(buffer3)); +#endif source->color[0] = g_ascii_strtod (buffer1, &endptr); source->color[1] = g_ascii_strtod (buffer2, &endptr); source->color[2] = g_ascii_strtod (buffer3, &endptr); @@ -1013,7 +1042,11 @@ load_preset_response (GtkFileChooser *chooser, snprintf (fmt_str, sizeof (fmt_str), " Intensity: %%%" G_GSIZE_FORMAT "s", sizeof (buffer1) - 1); +#ifndef _UCRT fscanf (fp, fmt_str, buffer1); +#else + fscanf_s (fp, fmt_str, buffer1, (unsigned int)sizeof(buffer1)); +#endif source->intensity = g_ascii_strtod (buffer1, &endptr); }