From d254c5684ca9fd05044a4cec29622e3f3583b4ac Mon Sep 17 00:00:00 2001 From: Bruno Lopes Date: Tue, 31 Mar 2026 15:20:15 -0300 Subject: [PATCH] app, libgimp*, plug-ins: Use strtok_s on Windows to fix CRT_INSECURE_DEPRECATE --- app/core/gimppalette-load.c | 20 ++++++++++++ app/path/gimppath-import.c | 19 +++++++++++ app/plug-in/gimppluginprocedure.c | 11 +++++++ libgimpbase/gimpparasiteio.c | 7 +++++ plug-ins/imagemap/imap_csim_parse.c | 47 +++++++++++++++++++++++++++- plug-ins/imagemap/imap_main.c | 28 ++++++++++++++--- plug-ins/imagemap/imap_preferences.c | 29 ++++++++++++++++- plug-ins/metadata/metadata-editor.c | 9 ++++++ 8 files changed, 164 insertions(+), 6 deletions(-) diff --git a/app/core/gimppalette-load.c b/app/core/gimppalette-load.c index a962651007..e12e66e06b 100644 --- a/app/core/gimppalette-load.c +++ b/app/core/gimppalette-load.c @@ -198,8 +198,15 @@ gimp_palette_load (GimpContext *context, { GeglColor *color = gegl_color_new ("black"); guint8 rgb[3] = { 0 }; +#ifdef _UCRT + gchar *context = NULL; +#endif +#ifndef _UCRT tok = strtok (str, " \t"); +#else + tok = strtok_s (str, " \t", &context); +#endif if (tok) { if (atoi (tok) < 0 || atoi (tok) > 255) @@ -216,7 +223,12 @@ gimp_palette_load (GimpContext *context, gimp_file_get_utf8_name (file), linenum); } +#ifndef _UCRT tok = strtok (NULL, " \t"); +#else + tok = strtok_s (NULL, " \t", &context); +#endif + if (tok) { if (atoi (tok) < 0 || atoi (tok) > 255) @@ -233,7 +245,11 @@ gimp_palette_load (GimpContext *context, gimp_file_get_utf8_name (file), linenum); } +#ifndef _UCRT tok = strtok (NULL, " \t"); +#else + tok = strtok_s (NULL, " \t", &context); +#endif if (tok) { if (atoi (tok) < 0 || atoi (tok) > 255) @@ -251,7 +267,11 @@ gimp_palette_load (GimpContext *context, } /* optional name */ +#ifndef _UCRT tok = strtok (NULL, "\n"); +#else + tok = strtok_s (NULL, "\n", &context); +#endif /* Historical .gpl format is sRGB. */ gegl_color_set_pixel (color, babl_format ("R'G'B' u8"), rgb); diff --git a/app/path/gimppath-import.c b/app/path/gimppath-import.c index dff872e228..3fa25b3c1e 100644 --- a/app/path/gimppath-import.c +++ b/app/path/gimppath-import.c @@ -1220,22 +1220,41 @@ parse_svg_viewbox (const gchar *value, gchar *tok; gchar *str = g_strdup (value); gboolean success = FALSE; +#ifdef _UCRT + gchar *context = NULL; +#endif x = y = w = h = 0; +#ifndef _UCRT tok = strtok (str, ", \t"); +#else + tok = strtok_s (str, ", \t", &context); +#endif if (tok) { x = g_ascii_strtod (tok, NULL); +#ifndef _UCRT tok = strtok (NULL, ", \t"); +#else + tok = strtok_s (NULL, ", \t", &context); +#endif if (tok) { y = g_ascii_strtod (tok, NULL); +#ifndef _UCRT tok = strtok (NULL, ", \t"); +#else + tok = strtok_s (NULL, ", \t", &context); +#endif if (tok != NULL) { w = g_ascii_strtod (tok, NULL); +#ifndef _UCRT tok = strtok (NULL, ", \t"); +#else + tok = strtok_s (NULL, ", \t", &context); +#endif if (tok) { h = g_ascii_strtod (tok, NULL); diff --git a/app/plug-in/gimppluginprocedure.c b/app/plug-in/gimppluginprocedure.c index 6f42f45b11..55b0348c55 100644 --- a/app/plug-in/gimppluginprocedure.c +++ b/app/plug-in/gimppluginprocedure.c @@ -1117,17 +1117,28 @@ extensions_parse (gchar *extensions) { gchar *extension; gchar *next_token; +#ifdef _UCRT + gchar *context = NULL; +#endif /* work on a copy */ extensions = g_strdup (extensions); next_token = extensions; +#ifndef _UCRT extension = strtok (next_token, " \t,"); +#else + extension = strtok_s (next_token, " \t,", &context); +#endif while (extension) { list = g_slist_prepend (list, g_strdup (extension)); +#ifndef _UCRT extension = strtok (NULL, " \t,"); +#else + extension = strtok_s (NULL, " \t,", &context); +#endif } g_free (extensions); diff --git a/libgimpbase/gimpparasiteio.c b/libgimpbase/gimpparasiteio.c index 36b621ea44..2d57637543 100644 --- a/libgimpbase/gimpparasiteio.c +++ b/libgimpbase/gimpparasiteio.c @@ -101,6 +101,9 @@ gimp_pixpipe_params_parse (const gchar *parameters, gchar *copy; gchar *p, *q, *r; gint i; +#ifdef _UCRT + gchar *context = NULL; +#endif g_return_if_fail (parameters != NULL); g_return_if_fail (params != NULL); @@ -108,7 +111,11 @@ gimp_pixpipe_params_parse (const gchar *parameters, copy = g_strdup (parameters); q = copy; +#ifndef _UCRT while ((p = strtok (q, " \r\n")) != NULL) +#else + while ((p = strtok_s (q, " \r\n", &context)) != NULL) +#endif { q = NULL; r = strchr (p, ':'); diff --git a/plug-ins/imagemap/imap_csim_parse.c b/plug-ins/imagemap/imap_csim_parse.c index dd1b776804..cd883aa01d 100644 --- a/plug-ins/imagemap/imap_csim_parse.c +++ b/plug-ins/imagemap/imap_csim_parse.c @@ -1692,28 +1692,57 @@ yyreduce: /* Line 1787 of yacc.c */ #line 200 "imap_csim.y" { - char *p; + char *p; + gchar *context = NULL; if (current_type == RECTANGLE) { Rectangle_t *rectangle; rectangle = ObjectToRectangle(current_object); +#ifndef _UCRT p = strtok((yyvsp[(3) - (3)].id), ","); +#else + p = strtok_s((yyvsp[(3) - (3)].id), ",", &context); +#endif rectangle->x = atoi(p); +#ifndef _UCRT p = strtok(NULL, ","); +#else + p = strtok_s(NULL, ",", &context); +#endif rectangle->y = atoi(p); +#ifndef _UCRT p = strtok(NULL, ","); +#else + p = strtok_s(NULL, ",", &context); +#endif rectangle->width = atoi(p) - rectangle->x; +#ifndef _UCRT p = strtok(NULL, ","); +#else + p = strtok_s(NULL, ",", &context); +#endif rectangle->height = atoi(p) - rectangle->y; } else if (current_type == CIRCLE) { Circle_t *circle; circle = ObjectToCircle(current_object); +#ifndef _UCRT p = strtok((yyvsp[(3) - (3)].id), ","); +#else + p = strtok_s((yyvsp[(3) - (3)].id), ",", &context); +#endif circle->x = atoi(p); +#ifndef _UCRT p = strtok(NULL, ","); +#else + p = strtok_s(NULL, ",", &context); +#endif circle->y = atoi(p); +#ifndef _UCRT p = strtok(NULL, ","); +#else + p = strtok_s(NULL, ",", &context); +#endif circle->r = atoi(p); } else if (current_type == POLYGON) { Polygon_t *polygon = ObjectToPolygon(current_object); @@ -1721,19 +1750,35 @@ yyreduce: GdkPoint *point, *first; gint x, y; +#ifndef _UCRT p = strtok((yyvsp[(3) - (3)].id), ","); +#else + p = strtok_s((yyvsp[(3) - (3)].id), ",", &context); +#endif x = atoi(p); +#ifndef _UCRT p = strtok(NULL, ","); +#else + p = strtok_s(NULL, ",", &context); +#endif y = atoi(p); point = new_point(x, y); points = g_list_append(NULL, (gpointer) point); while(1) { +#ifndef _UCRT p = strtok(NULL, ","); +#else + p = strtok_s(NULL, ",", &context); +#endif if (!p) break; x = atoi(p); +#ifndef _UCRT p = strtok(NULL, ","); +#else + p = strtok_s(NULL, ",", &context); +#endif y = atoi(p); point = new_point(x, y); points = g_list_append(points, (gpointer) point); diff --git a/plug-ins/imagemap/imap_main.c b/plug-ins/imagemap/imap_main.c index ee7e54bbea..3a3843b4fc 100644 --- a/plug-ins/imagemap/imap_main.c +++ b/plug-ins/imagemap/imap_main.c @@ -923,6 +923,9 @@ save_as_cern(gpointer param, OutputFunc_t output) char *p; gchar *description; gchar *next_token; +#ifdef _UCRT + gchar *context = NULL; +#endif write_cern_comment(param, output); output(param, "-:Image map file created by GIMP Image Map plug-in\n"); @@ -941,10 +944,15 @@ save_as_cern(gpointer param, OutputFunc_t output) description = g_strdup(_map_info.description); next_token = description; - for (p = strtok (next_token, "\n"); p; p = strtok(NULL, "\n")) { - write_cern_comment(param, output); - output(param, "DESCRIPTION:%s\n", p); - } +#ifndef _UCRT + for (p = strtok (next_token, "\n"); p; p = strtok(NULL, "\n")) +#else + for (p = strtok_s (next_token, "\n", &context); p; p = strtok_s(NULL, "\n", &context)) +#endif + { + write_cern_comment(param, output); + output(param, "DESCRIPTION:%s\n", p); + } g_free(description); if (*_map_info.default_url) @@ -957,6 +965,9 @@ save_as_csim(gpointer param, OutputFunc_t output) { char *p; gchar *description; +#ifdef _UCRT + gchar *context = NULL; +#endif output(param, "\n\n", _map_info.image_name, @@ -971,7 +982,11 @@ save_as_csim(gpointer param, OutputFunc_t output) output(param, "\n", _map_info.author); description = g_strdup(_map_info.description); +#ifndef _UCRT for (p = strtok(description, "\n"); p; p = strtok(NULL, "\n")) +#else + for (p = strtok_s(description, "\n", &context); p; p = strtok_s(NULL, "\n", &context)) +#endif output(param, "\n", p); g_free(description); @@ -987,6 +1002,7 @@ save_as_ncsa(gpointer param, OutputFunc_t output) { char *p; gchar *description; + gchar *context = NULL; output(param, "#$-:Image map file created by GIMP Image Map plug-in\n"); output(param, "#$-:GIMP Image Map plug-in by Maurits Rijk\n"); @@ -997,7 +1013,11 @@ save_as_ncsa(gpointer param, OutputFunc_t output) output(param, "#$FORMAT:ncsa\n"); description = g_strdup(_map_info.description); +#ifndef _UCRT for (p = strtok(description, "\n"); p; p = strtok(NULL, "\n")) +#else + for (p = strtok_s(description, "\n", &context); p; p = strtok_s(NULL, "\n", &context)) +#endif output(param, "#$DESCRIPTION:%s\n", p); g_free(description); diff --git a/plug-ins/imagemap/imap_preferences.c b/plug-ins/imagemap/imap_preferences.c index d9c049a6e8..e623b65509 100644 --- a/plug-ins/imagemap/imap_preferences.c +++ b/plug-ins/imagemap/imap_preferences.c @@ -76,7 +76,12 @@ static void get_button_colors (PreferencesDialog_t *dialog, static gint parse_map_type(void) { +#ifndef _UCRT char *token = strtok(NULL, " )"); +#else + gchar *context = NULL; + char *token = strtok_s(NULL, " )", &context); +#endif if (!strcmp(token, "ncsa")) return NCSA; else if (!strcmp(token, "cern")) @@ -87,14 +92,24 @@ parse_map_type(void) static gint parse_yes_no(void) { +#ifndef _UCRT char *token = strtok(NULL, " )"); +#else + gchar *context = NULL; + char *token = strtok_s(NULL, " )", &context); +#endif return (gint) strcmp(token, "no"); } static gint parse_int(void) { +#ifndef _UCRT char *token = strtok(NULL, " )"); +#else + gchar *context = NULL; + char *token = strtok_s(NULL, " )", &context); +#endif return (gint) atoi(token); } @@ -110,18 +125,30 @@ parse_color(GdkRGBA *color) static void parse_mru_entry(void) { +#ifndef _UCRT char *filename = strtok(NULL, " )"); +#else + gchar *context = NULL; + char *filename = strtok_s(NULL, " )", &context); +#endif mru_add(get_mru(), filename); } static void parse_line(PreferencesData_t *data, char *line) { - char *token; + char *token; ColorSelData_t *colors = &data->colors; +#ifdef _UCRT + gchar *context = NULL; +#endif line++; /* Skip '(' */ +#ifndef _UCRT token = strtok(line, " "); +#else + token = strtok_s(line, " ", &context); +#endif if (!strcmp(token, "default-map-type")) { data->default_map_type = parse_map_type(); diff --git a/plug-ins/metadata/metadata-editor.c b/plug-ins/metadata/metadata-editor.c index 0db6eda909..dd448967ab 100644 --- a/plug-ins/metadata/metadata-editor.c +++ b/plug-ins/metadata/metadata-editor.c @@ -4879,14 +4879,23 @@ set_gps_longitude_latitude (GimpMetadata *metadata, gint degrees, minutes; gdouble seconds; gboolean remove_val = FALSE; +#ifdef _UCRT + gchar *context = NULL; +#endif g_log (ME_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "set_gps_longitude_latitude - Tag %s, Input value: %s", tag, value); if (s && s[0] != '\0') { +#ifndef _UCRT str1 = strtok (s, delimiters_dms); str2 = strtok (NULL, delimiters_dms); str3 = strtok (NULL, delimiters_dms); +#else + str1 = strtok_s (s, delimiters_dms, &context); + str2 = strtok_s (NULL, delimiters_dms, &context); + str3 = strtok_s (NULL, delimiters_dms, &context); +#endif g_log (ME_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "String split into: %s - %s - %s", str1, str2, str3); }