app, lib*, plug-ins: Use sscanf_s on Windows to fix CRT_INSECURE_DEPRECATE warns

This commit is contained in:
Bruno Lopes 2026-03-30 20:02:51 -03:00
parent 6f33a6a896
commit 2066844166
28 changed files with 245 additions and 0 deletions

View file

@ -1146,7 +1146,11 @@ gimp_image_window_set_aux_info (GimpSessionManaged *session_managed,
maximized = TRUE;
if (width)
#ifndef _UCRT
sscanf (aux->value, "%d", width);
#else
sscanf_s (aux->value, "%d", width);
#endif
/* compat handling for right docks */
if (! strcmp (aux->name, GIMP_IMAGE_WINDOW_RIGHT_DOCKS_POS))

View file

@ -587,8 +587,13 @@ gimp_curves_config_load_cruft (GimpCurvesConfig *config,
return FALSE;
}
#ifndef _UCRT
if (sscanf (x_str, "%d", &index[i][j]) != 1 ||
sscanf (y_str, "%d", &value[i][j]) != 1)
#else
if (sscanf_s (x_str, "%d", &index[i][j]) != 1 ||
sscanf_s (y_str, "%d", &value[i][j]) != 1)
#endif
{
g_set_error_literal (error,
GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,

View file

@ -588,7 +588,11 @@ file_convert_string (const gchar *instr,
}
*tmpptr = '\0';
#ifndef _UCRT
sscanf ((gchar *) tmp, "%o", &k);
#else
sscanf_s ((gchar *) tmp, "%o", &k);
#endif
*(uout++) = k;
break;
@ -626,7 +630,12 @@ file_check_single_magic (const gchar *offset,
gchar num_operator;
/* Check offset */
#ifndef _UCRT
if (sscanf (offset, "%ld", &offs) != 1)
#else
if (sscanf_s (offset, "%ld", &offs) != 1)
#endif
return FILE_MATCH_NONE;
/* Check type of test */
@ -667,11 +676,23 @@ file_check_single_magic (const gchar *offset,
if (g_ascii_isdigit (num_operator_ptr[1]))
{
if (num_operator_ptr[1] != '0') /* decimal */
#ifndef _UCRT
sscanf (num_operator_ptr+1, "%lu", &num_operator_val);
#else
sscanf_s (num_operator_ptr+1, "%lu", &num_operator_val);
#endif
else if (num_operator_ptr[2] == 'x') /* hexadecimal */
#ifndef _UCRT
sscanf (num_operator_ptr+3, "%lx", &num_operator_val);
#else
sscanf_s (num_operator_ptr+3, "%lx", &num_operator_val);
#endif
else /* octal */
#ifndef _UCRT
sscanf (num_operator_ptr+2, "%lo", &num_operator_val);
#else
sscanf_s (num_operator_ptr+2, "%lo", &num_operator_val);
#endif
num_operator = *num_operator_ptr;
}

View file

@ -2589,7 +2589,11 @@ gimp_dashboard_sample_memory_used (GimpDashboard *dashboard,
buffer[size] = '\0';
#ifndef _UCRT
if (sscanf (buffer, "%*u %llu %llu", &resident, &shared) != 2)
#else
if (sscanf_s (buffer, "%*u %llu %llu", &resident, &shared) != 2)
#endif
return;
variable_data->available = TRUE;

View file

@ -588,8 +588,13 @@ gimp_selection_data_get_image (GtkSelectionData *selection,
gint pid;
gint ID;
#ifndef _UCRT
if (sscanf (str, "%i:%i", &pid, &ID) == 2 &&
pid == gimp_get_pid ())
#else
if (sscanf_s (str, "%i:%i", &pid, &ID) == 2 &&
pid == gimp_get_pid ())
#endif
{
return gimp_image_get_by_id (gimp, ID);
}
@ -639,8 +644,13 @@ gimp_selection_data_get_component (GtkSelectionData *selection,
gint ID;
gint ch;
#ifndef _UCRT
if (sscanf (str, "%i:%i:%i", &pid, &ID, &ch) == 3 &&
pid == gimp_get_pid ())
#else
if (sscanf_s (str, "%i:%i:%i", &pid, &ID, &ch) == 3 &&
pid == gimp_get_pid ())
#endif
{
GimpImage *image = gimp_image_get_by_id (gimp, ID);
@ -688,8 +698,13 @@ gimp_selection_data_get_item (GtkSelectionData *selection,
gint pid;
gint ID;
#ifndef _UCRT
if (sscanf (str, "%i:%i", &pid, &ID) == 2 &&
pid == gimp_get_pid ())
#else
if (sscanf_s (str, "%i:%i", &pid, &ID) == 2 &&
pid == gimp_get_pid ())
#endif
{
return gimp_item_get_by_id (gimp, ID);
}
@ -961,8 +976,13 @@ gimp_selection_data_get_object (GtkSelectionData *selection,
gpointer object_addr;
gint name_offset = 0;
#ifndef _UCRT
if (sscanf (str, "%i:%p:%n", &pid, &object_addr, &name_offset) >= 2 &&
pid == gimp_get_pid () && name_offset > 0)
#else
if (sscanf_s (str, "%i:%p:%n", &pid, &object_addr, &name_offset) >= 2 &&
pid == gimp_get_pid () && name_offset > 0)
#endif
{
const gchar *name = str + name_offset;

View file

@ -1376,7 +1376,11 @@ gimp_text_buffer_name_to_tag (GimpTextBuffer *buffer,
guint r, g, b;
guchar rgb[3];
#ifndef _UCRT
sscanf (value, "#%02x%02x%02x", &r, &g, &b);
#else
sscanf_s (value, "#%02x%02x%02x", &r, &g, &b);
#endif
rgb[0] = r;
rgb[1] = g;
rgb[2] = b;

View file

@ -254,8 +254,13 @@ gimp_image_combo_box_drag_data_received (GtkWidget *widget,
gint pid;
gint ID;
#ifndef _UCRT
if (sscanf (str, "%i:%i", &pid, &ID) == 2 &&
pid == gimp_getpid ())
#else
if (sscanf_s (str, "%i:%i", &pid, &ID) == 2 &&
pid == gimp_getpid ())
#endif
{
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (widget), ID);
}

View file

@ -538,8 +538,13 @@ gimp_item_combo_box_drag_data_received (GtkWidget *widget,
gint pid;
gint ID;
#ifndef _UCRT
if (sscanf (str, "%i:%i", &pid, &ID) == 2 &&
pid == gimp_getpid ())
#else
if (sscanf_s (str, "%i:%i", &pid, &ID) == 2 &&
pid == gimp_getpid ())
#endif
{
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (widget), ID);
}

View file

@ -627,8 +627,13 @@ gimp_resource_select_drag_data_received (GimpResourceChooser *self,
gpointer unused;
gint name_offset = 0;
#ifndef _UCRT
if (sscanf (str, "%i:%p:%n", &pid, &unused, &name_offset) >= 2 &&
pid == gimp_getpid () && name_offset > 0)
#else
if (sscanf_s (str, "%i:%p:%n", &pid, &unused, &name_offset) >= 2 &&
pid == gimp_getpid () && name_offset > 0)
#endif
{
gchar *name = str + name_offset;
GimpResource *resource;

View file

@ -297,12 +297,20 @@ _br_find_exe_for_symbol (const void *symbol, GimpBinrelocInitError *error)
memcpy (address_string, "0x", 2);
memcpy (address_string + 2, start_addr, len);
address_string[2 + len] = '\0';
#ifndef _UCRT
sscanf (address_string, "%p", &start_addr_p);
#else
sscanf_s (address_string, "%p", &start_addr_p);
#endif
memcpy (address_string, "0x", 2);
memcpy (address_string + 2, end_addr, len);
address_string[2 + len] = '\0';
#ifndef _UCRT
sscanf (address_string, "%p", &end_addr_p);
#else
sscanf_s (address_string, "%p", &end_addr_p);
#endif
if (symbol >= start_addr_p && symbol < end_addr_p)
{

View file

@ -800,18 +800,30 @@ gimp_thumbnail_set_info_from_pixbuf (GimpThumbnail *thumbnail,
g_strdup (gdk_pixbuf_get_option (pixbuf, TAG_THUMB_MIMETYPE));
option = gdk_pixbuf_get_option (pixbuf, TAG_THUMB_IMAGE_WIDTH);
#ifndef _UCRT
if (option && sscanf (option, "%d", &num) == 1)
#else
if (option && sscanf_s (option, "%d", &num) == 1)
#endif
thumbnail->image_width = num;
option = gdk_pixbuf_get_option (pixbuf, TAG_THUMB_IMAGE_HEIGHT);
#ifndef _UCRT
if (option && sscanf (option, "%d", &num) == 1)
#else
if (option && sscanf_s (option, "%d", &num) == 1)
#endif
thumbnail->image_height = num;
thumbnail->image_type =
g_strdup (gdk_pixbuf_get_option (pixbuf, TAG_THUMB_GIMP_TYPE));
option = gdk_pixbuf_get_option (pixbuf, TAG_THUMB_GIMP_LAYERS);
#ifndef _UCRT
if (option && sscanf (option, "%d", &num) == 1)
#else
if (option && sscanf_s (option, "%d", &num) == 1)
#endif
thumbnail->image_num_layers = num;
g_object_thaw_notify (G_OBJECT (thumbnail));
@ -1066,11 +1078,19 @@ gimp_thumbnail_load_thumb (GimpThumbnail *thumbnail,
state = GIMP_THUMB_STATE_OLD;
option = gdk_pixbuf_get_option (pixbuf, TAG_THUMB_MTIME);
#ifndef _UCRT
if (!option || sscanf (option, "%" G_GINT64_FORMAT, &image_mtime) != 1)
#else
if (!option || sscanf_s (option, "%" G_GINT64_FORMAT, &image_mtime) != 1)
#endif
goto finish;
option = gdk_pixbuf_get_option (pixbuf, TAG_THUMB_FILESIZE);
#ifndef _UCRT
if (option && sscanf (option, "%" G_GINT64_FORMAT, &image_size) != 1)
#else
if (option && sscanf_s (option, "%" G_GINT64_FORMAT, &image_size) != 1)
#endif
goto finish;
/* TAG_THUMB_FILESIZE is optional but must match if present */
@ -1424,11 +1444,19 @@ gimp_thumbnail_has_failed (GimpThumbnail *thumbnail)
goto finish;
option = gdk_pixbuf_get_option (pixbuf, TAG_THUMB_MTIME);
#ifndef _UCRT
if (!option || sscanf (option, "%" G_GINT64_FORMAT, &image_mtime) != 1)
#else
if (!option || sscanf_s (option, "%" G_GINT64_FORMAT, &image_mtime) != 1)
#endif
goto finish;
option = gdk_pixbuf_get_option (pixbuf, TAG_THUMB_FILESIZE);
#ifndef _UCRT
if (option && sscanf (option, "%" G_GINT64_FORMAT, &image_size) != 1)
#else
if (option && sscanf_s (option, "%" G_GINT64_FORMAT, &image_size) != 1)
#endif
goto finish;
/* TAG_THUMB_FILESIZE is optional but must match if present */

View file

@ -894,10 +894,18 @@ gimp_page_selector_select_range (GimpPageSelector *selector,
from = g_strstrip (range);
to = g_strstrip (dash + 1);
#ifndef _UCRT
if (sscanf (from, "%i", &page_from) != 1 && strlen (from) == 0)
#else
if (sscanf_s (from, "%i", &page_from) != 1 && strlen (from) == 0)
#endif
page_from = 1;
#ifndef _UCRT
if (sscanf (to, "%i", &page_to) != 1 && strlen (to) == 0)
#else
if (sscanf_s (to, "%i", &page_to) != 1 && strlen (to) == 0)
#endif
page_to = selector->n_pages;
if (page_from > 0 &&
@ -918,9 +926,15 @@ gimp_page_selector_select_range (GimpPageSelector *selector,
{
gint page_no;
#ifndef _UCRT
if (sscanf (range, "%i", &page_no) == 1 &&
page_no >= 1 &&
page_no <= selector->n_pages)
#else
if (sscanf_s (range, "%i", &page_no) == 1 &&
page_no >= 1 &&
page_no <= selector->n_pages)
#endif
{
gimp_page_selector_select_page (selector, page_no - 1);
}

View file

@ -829,8 +829,13 @@ p_load_pointfile (BenderDialog *cd,
if (strncmp (buff, KEY_POINTS, len) == 0)
{
#ifndef _UCRT
n = sscanf (&buff[len],
"%f %f %f %f", &fux, &fuy, &flx, &fly);
#else
n = sscanf_s (&buff[len],
"%f %f %f %f", &fux, &fuy, &flx, &fly);
#endif
if ((n == 4) && (pi < 17))
{
@ -850,7 +855,11 @@ p_load_pointfile (BenderDialog *cd,
if (strncmp (buff, KEY_VAL_Y, len) == 0)
{
#ifndef _UCRT
n = sscanf (&buff[len], "%d %d", &iuy, &ily);
#else
n = sscanf_s (&buff[len], "%d %d", &iuy, &ily);
#endif
if ((n == 2) && (ci < 256))
{

View file

@ -309,7 +309,11 @@ gif_export (GimpProcedure *procedure,
parasite_data = (gchar *) gimp_parasite_get_data (parasite, &parasite_size);
parasite_data = g_strndup (parasite_data, parasite_size);
#ifndef _UCRT
if (sscanf (parasite_data, "%i", &num_loops) == 1)
#else
if (sscanf_s (parasite_data, "%i", &num_loops) == 1)
#endif
{
gboolean loop = (num_loops == 0);

View file

@ -1192,7 +1192,11 @@ load_image (GFile *file,
{
if ((*temp < '0') || (*temp > '9'))
continue; /* Search next digit */
#ifndef _UCRT
sscanf (temp, "%d", &k);
#else
sscanf_s (temp, "%d", &k);
#endif
if (k > max_pagenum)
max_pagenum = k;
while ((*temp >= '0') && (*temp <= '9'))
@ -1814,7 +1818,11 @@ get_bbox (GFile *file,
src += 11;
while ((*src == ' ') || (*src == '\t') || (*src == ':')) src++;
if (strncmp (src, "(atend)", 7) == 0) continue;
#ifndef _UCRT
if (sscanf (src, "%d%d%d%d", x0, y0, x1, y1) == 4)
#else
if (sscanf_s (src, "%d%d%d%d", x0, y0, x1, y1) == 4)
#endif
retval = 0;
break;
}
@ -2162,7 +2170,11 @@ read_pnmraw_type (FILE *ifp,
if (line[0] != '#')
break;
}
#ifndef _UCRT
if (sscanf (line, "%d%d", width, height) != 2)
#else
if (sscanf_s (line, "%d%d", width, height) != 2)
#endif
return -1;
*maxval = 255;
@ -2176,7 +2188,11 @@ read_pnmraw_type (FILE *ifp,
if (line[0] != '#')
break;
}
#ifndef _UCRT
if (sscanf (line, "%d", maxval) != 1)
#else
if (sscanf_s (line, "%d", maxval) != 1)
#endif
return -1;
}
@ -3745,7 +3761,12 @@ count_ps_pages (GFile *file)
fgets (buf, sizeof (buf), psfile);
if (strncmp (buf + 2, "Pages:", 6) == 0)
#ifndef _UCRT
sscanf (buf + strlen ("%%Pages:"), "%d", &num_pages);
#else
sscanf_s (buf + strlen ("%%Pages:"), "%d", &num_pages);
#endif
else if (strncmp (buf, "showpage", 8) == 0)
showpage_count++;
}

View file

@ -382,7 +382,11 @@ xbm_export (GimpProcedure *procedure,
parasite_data = (gchar *) gimp_parasite_get_data (parasite, &parasite_size);
parasite_data = g_strndup (parasite_data, parasite_size);
#ifndef _UCRT
if (sscanf (parasite_data, "%i %i", &x, &y) == 2)
#else
if (sscanf_s (parasite_data, "%i %i", &x, &y) == 2)
#endif
{
g_object_set (config,
"use-hot-spot", TRUE,

View file

@ -1888,7 +1888,11 @@ get_filevalues (void)
if (fp != NULL)
{
fgets (buf, 999, fp);
#ifndef _UCRT
sscanf (buf, "%f", &g_values.tol_col_err);
#else
sscanf_s (buf, "%f", &g_values.tol_col_err);
#endif
fclose (fp);
}

View file

@ -2115,7 +2115,11 @@ loadit (const gchar * fn)
t = &s.com.texture[i];
setdefaults (t);
#ifndef _UCRT
if (sscanf (line, fmt_str, &t->majtype, &t->type, end) != 3)
#else
if (sscanf_s (line, fmt_str, &t->majtype, &t->type, end) != 3)
#endif
t->color1.x = g_ascii_strtod (end, &end);
if (end && errno != ERANGE)
t->color1.y = g_ascii_strtod (end, &end);

View file

@ -534,9 +534,15 @@ write_dds (GFile *file,
&parasite_size);
parasite_data = g_strndup (parasite_data, parasite_size);
#ifndef _UCRT
n_params = sscanf (parasite_data, "%d %d %d %d %d %d", &version,
&comp_format, &d3d9_format, &dxgi_format, &flags,
&n_mipmaps);
#else
n_params = sscanf_s (parasite_data, "%d %d %d %d %d %d", &version,
&comp_format, &d3d9_format, &dxgi_format, &flags,
&n_mipmaps);
#endif
if (n_params == 6)
{
const gchar *config_comp_format;

View file

@ -345,7 +345,11 @@ ico_save_dialog (GimpImage *image,
parasite_data = (gchar *) gimp_parasite_get_data (parasite, &parasite_size);
parasite_data = g_strndup (parasite_data, parasite_size);
#ifndef _UCRT
if (sscanf (parasite_data, "%i %i", &x, &y) == 2)
#else
if (sscanf_s (parasite_data, "%i %i", &x, &y) == 2)
#endif
{
info->hot_spot_x[i] = x;
info->hot_spot_y[i] = y;
@ -1308,7 +1312,11 @@ ani_export_image (GFile *file,
parasite_data = (gchar *) gimp_parasite_get_data (parasite, &parasite_size);
parasite_data = g_strndup (parasite_data, parasite_size);
#ifndef _UCRT
if (sscanf (parasite_data, "%i", &jif_rate) == 1)
#else
if (sscanf_s (parasite_data, "%i", &jif_rate) == 1)
#endif
{
header->jif_rate = jif_rate;
}

View file

@ -138,10 +138,17 @@ anotherrawtherapee_init_procedures (GimpPlugIn *plug_in)
gint rtmajor = 0;
gint rtminor = 0;
#ifndef _UCRT
if (sscanf (art_stdout,
"ART, version %d.%d",
&rtmajor, &rtminor) == 2 &&
((rtmajor == 1 && rtminor >= 20) || rtmajor >= 2))
#else
if (sscanf_s (art_stdout,
"ART, version %d.%d",
&rtmajor, &rtminor) == 2 &&
((rtmajor == 1 && rtminor >= 20) || rtmajor >= 2))
#endif
{
have_art = TRUE;
}

View file

@ -654,7 +654,11 @@ load_thumbnail_image (GFile *file,
darktable_file = g_file_new_for_path (response[i + 1]);
image = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
darktable_file);
#ifndef _UCRT
sscanf (response[i + 2], "%d %d", width, height);
#else
sscanf_s (response[i + 2], "%d %d", width, height);
#endif
g_object_unref (darktable_file);
break;
@ -690,7 +694,11 @@ load_thumbnail_image (GFile *file,
-1,
"[dt4gimp]");
if (start_of_size)
#ifndef _UCRT
sscanf (start_of_size, "[dt4gimp] %d %d", width, height);
#else
sscanf_s (start_of_size, "[dt4gimp] %d %d", width, height);
#endif
}
}
}

View file

@ -138,10 +138,17 @@ rawtherapee_init_procedures (GimpPlugIn *plug_in)
gint rtmajor = 0;
gint rtminor = 0;
#ifndef _UCRT
if (sscanf (rawtherapee_stdout,
"RawTherapee, version %d.%d",
&rtmajor, &rtminor) == 2 &&
((rtmajor == 5 && rtminor >= 2) || rtmajor >= 6))
#else
if (sscanf_s (rawtherapee_stdout,
"RawTherapee, version %d.%d",
&rtmajor, &rtminor) == 2 &&
((rtmajor == 5 && rtminor >= 2) || rtmajor >= 6))
#endif
{
have_rawtherapee = TRUE;
}

View file

@ -120,7 +120,11 @@ d_load_object (gchar *desc,
while (get_line (buf, MAX_LOAD_LINE, fp, 0))
{
#ifndef _UCRT
if (sscanf (buf, "%d %d", &xpnt, &ypnt) != 2)
#else
if (sscanf_s (buf, "%d %d", &xpnt, &ypnt) != 2)
#endif
{
/* Read <EXTRA> block if there is one */
if (!strcmp ("<EXTRA>", buf))
@ -133,7 +137,11 @@ d_load_object (gchar *desc,
get_line (buf, MAX_LOAD_LINE, fp, 0);
#ifndef _UCRT
if (sscanf (buf, "%d", &new_obj->type_data) != 1)
#else
if (sscanf_s (buf, "%d", &new_obj->type_data) != 1)
#endif
{
g_message ("Error while loading object (no type data)");
g_free (new_obj);

View file

@ -386,7 +386,11 @@ gfig_name_decode (gchar *dest,
{
if (*src == '\\' && *(src+1) && *(src+2) && *(src+3))
{
#ifndef _UCRT
sscanf (src+1, "%3o", &tmp);
#else
sscanf_s (src+1, "%3o", &tmp);
#endif
*dest++ = tmp;
src += 4;
}
@ -562,7 +566,11 @@ gfig_load (GimpGfig *gfig,
gfig_obj->version = g_ascii_strtod (load_buf + 9, NULL);
get_line (load_buf, MAX_LOAD_LINE, fp, 0);
#ifndef _UCRT
sscanf (load_buf, "ObjCount: %d", &load_count);
#else
sscanf_s (load_buf, "ObjCount: %d", &load_count);
#endif
if (load_options (gfig_obj, fp))
{

View file

@ -4789,7 +4789,11 @@ gradient_name_decode (gchar *dest,
{
if (*src == '\\' && *(src+1) && *(src+2) && *(src+3))
{
#ifndef _UCRT
sscanf (src+1, "%3o", &tmp);
#else
sscanf_s (src+1, "%3o", &tmp);
#endif
*dest++ = tmp;
src += 4;
}

View file

@ -1673,7 +1673,11 @@ on_date_button_clicked (GtkButton *widget,
date_text = gtk_entry_get_text (GTK_ENTRY (entry_widget));
if (date_text && date_text[0] != '\0')
{
#ifndef _UCRT
sscanf (date_text, "%u-%u-%u;", &year, &month, &day);
#else
sscanf_s (date_text, "%u-%u-%u;", &year, &month, &day);
#endif
month--;
}
else

View file

@ -1338,14 +1338,26 @@ static pointer mk_sharp_const(scheme *sc, char *name) {
return (sc->F);
else if (*name == 'o') {/* #o (octal) */
snprintf(tmp, STRBUFFSIZE, "0%s", name+1);
#ifndef _UCRT
sscanf(tmp, "%lo", (long unsigned *)&x);
#else
sscanf_s(tmp, "%lo", (long unsigned *)&x);
#endif
return (mk_integer(sc, x));
} else if (*name == 'd') { /* #d (decimal) */
#ifndef _UCRT
sscanf(name+1, "%ld", (long int *)&x);
#else
sscanf_s(name+1, "%ld", (long int *)&x);
#endif
return (mk_integer(sc, x));
} else if (*name == 'x') { /* #x (hex) */
snprintf(tmp, STRBUFFSIZE, "0x%s", name+1);
#ifndef _UCRT
sscanf(tmp, "%lx", (long unsigned *)&x);
#else
sscanf_s(tmp, "%lx", (long unsigned *)&x);
#endif
return (mk_integer(sc, x));
} else if (*name == 'b') { /* #b (binary) */
x = binary_decode(name+1);
@ -1371,7 +1383,11 @@ static pointer mk_sharp_const(scheme *sc, char *name) {
}
else {
/* #\x<[0-f]*> Convert hex literal to codepoint. */
#ifndef _UCRT
if(sscanf(name+2,"%x",(unsigned int *)&codepoint)!=1) {
#else
if(sscanf_s(name+2,"%x",(unsigned int *)&codepoint)!=1) {
#endif
g_warning ("Hex literal has invalid digits");
return sc->NIL;
}