[gimp] Use g_strlcpy() instead of strncpy() everywhere



commit b007269729597c80881c6dfad63d4f76aa673558
Author: Michael Natterer <mitch gimp org>
Date:   Wed Aug 14 23:52:38 2019 +0200

    Use g_strlcpy() instead of strncpy() everywhere
    
    except where I didn't understand the code after 10 seconds of
    looking..

 app/text/gimptext-xlfd.c                 |  3 +--
 libgimpbase/gimpmetadata.c               |  3 +--
 libgimpbase/gimpreloc.c                  |  4 ++--
 plug-ins/common/cml-explorer.c           |  8 +++----
 plug-ins/common/compose.c                |  5 ++--
 plug-ins/common/decompose.c              |  9 ++++---
 plug-ins/common/file-dicom.c             | 11 +++------
 plug-ins/common/file-gbr.c               | 26 ++++++++-------------
 plug-ins/common/file-gif-load.c          |  3 +--
 plug-ins/common/file-gih.c               | 26 +++++++--------------
 plug-ins/common/file-html-table.c        |  2 +-
 plug-ins/common/file-pat.c               | 26 +++++++--------------
 plug-ins/common/file-ps.c                | 22 +++++++-----------
 plug-ins/common/file-xbm.c               | 40 ++++++++++++--------------------
 plug-ins/common/plugin-browser.c         |  3 +--
 plug-ins/common/qbist.c                  |  4 ++--
 plug-ins/common/web-page.c               |  3 +--
 plug-ins/file-fits/fits-io.c             |  5 +---
 plug-ins/gradient-flare/gradient-flare.c |  9 +++----
 plug-ins/screenshot/screenshot-win32.c   |  2 +-
 plug-ins/script-fu/script-fu-server.c    |  2 +-
 21 files changed, 81 insertions(+), 135 deletions(-)
---
diff --git a/app/text/gimptext-xlfd.c b/app/text/gimptext-xlfd.c
index 287e39213c..d542f8c4e1 100644
--- a/app/text/gimptext-xlfd.c
+++ b/app/text/gimptext-xlfd.c
@@ -263,8 +263,7 @@ gimp_text_get_xlfd_field (const gchar *fontname,
       if (*t1 == '*')
         return NULL;
 
-      strncpy (buffer, t1, len);
-      buffer[len] = 0;
+      g_strlcpy (buffer, t1, len);
 
       /* Convert to lower case. */
       for (p = buffer; *p; p++)
diff --git a/libgimpbase/gimpmetadata.c b/libgimpbase/gimpmetadata.c
index 44cf87e794..9ebfae8c48 100644
--- a/libgimpbase/gimpmetadata.c
+++ b/libgimpbase/gimpmetadata.c
@@ -584,8 +584,7 @@ gimp_metadata_deserialize_start_element (GMarkupParseContext *context,
           return;
         }
 
-      strncpy (parse_data->name, name, sizeof (parse_data->name));
-      parse_data->name[sizeof (parse_data->name) - 1] = 0;
+      g_strlcpy (parse_data->name, name, sizeof (parse_data->name));
 
       parse_data->base64 = (encoding && ! strcmp (encoding, "base64"));
     }
diff --git a/libgimpbase/gimpreloc.c b/libgimpbase/gimpreloc.c
index b9fa4df67f..7ed1783b3c 100644
--- a/libgimpbase/gimpreloc.c
+++ b/libgimpbase/gimpreloc.c
@@ -70,7 +70,7 @@ _br_find_exe (GimpBinrelocInitError *error)
       return NULL;
     }
 
-  strncpy (path2, "/proc/self/exe", buf_size - 1);
+  g_strlcpy (path2, "/proc/self/exe", buf_size);
 
   while (1)
     {
@@ -106,7 +106,7 @@ _br_find_exe (GimpBinrelocInitError *error)
         }
 
       /* path is a symlink. Continue loop and resolve this. */
-      strncpy (path, path2, buf_size - 1);
+      g_strlcpy (path, path2, buf_size);
     }
 
 
diff --git a/plug-ins/common/cml-explorer.c b/plug-ins/common/cml-explorer.c
index 44653cbedd..745056b65e 100644
--- a/plug-ins/common/cml-explorer.c
+++ b/plug-ins/common/cml-explorer.c
@@ -2158,8 +2158,8 @@ CML_save_to_file_response (GtkWidget *dialog,
   g_message (_("Parameters were saved to '%s'"),
              gimp_filename_to_utf8 (filename));
 
-  strncpy (VALS.last_file_name, filename,
-           sizeof (VALS.last_file_name) - 1);
+  g_strlcpy (VALS.last_file_name, filename,
+             sizeof (VALS.last_file_name));
 
   g_free (filename);
 
@@ -2391,8 +2391,8 @@ CML_load_parameter_file (const gchar *filename,
                   sizeof (CML_PARAM));
         }
 
-      strncpy (VALS.last_file_name, filename,
-               sizeof (VALS.last_file_name) - 1);
+      g_strlcpy (VALS.last_file_name, filename,
+                 sizeof (VALS.last_file_name));
     }
   return flag;
 }
diff --git a/plug-ins/common/compose.c b/plug-ins/common/compose.c
index 9b0f6b005b..902375b673 100644
--- a/plug-ins/common/compose.c
+++ b/plug-ins/common/compose.c
@@ -574,9 +574,8 @@ run (const gchar      *name,
               composevals.inputs[2].comp.ID = param[4].data.d_int32;
               composevals.inputs[3].comp.ID = param[5].data.d_int32;
 
-              strncpy (composevals.compose_type, param[6].data.d_string,
-                       sizeof (composevals.compose_type));
-              composevals.compose_type[sizeof (composevals.compose_type)-1] = '\0';
+              g_strlcpy (composevals.compose_type, param[6].data.d_string,
+                         sizeof (composevals.compose_type));
 
               for (i = 0; i < MAX_COMPOSE_IMAGES; i++)
                 {
diff --git a/plug-ins/common/decompose.c b/plug-ins/common/decompose.c
index 39a7dce5bc..c4fac350cd 100644
--- a/plug-ins/common/decompose.c
+++ b/plug-ins/common/decompose.c
@@ -359,9 +359,8 @@ run (const gchar      *name,
         }
       else
         {
-          strncpy (decovals.extract_type, param[3].data.d_string,
-                   sizeof (decovals.extract_type));
-          decovals.extract_type[sizeof (decovals.extract_type) - 1] = '\0';
+          g_strlcpy (decovals.extract_type, param[3].data.d_string,
+                     sizeof (decovals.extract_type));
 
           decovals.as_layers = nparams > 4 ? param[4].data.d_int32 : FALSE;
           decovals.use_registration = (strcmp (name, PLUG_IN_PROC_REG) == 0);
@@ -917,8 +916,8 @@ decompose_dialog (void)
   gtk_widget_destroy (dialog);
 
   if (run)
-    strncpy (decovals.extract_type, extract[extract_idx].type,
-             sizeof decovals.extract_type - 1);
+    g_strlcpy (decovals.extract_type, extract[extract_idx].type,
+               sizeof decovals.extract_type);
 
   return run;
 }
diff --git a/plug-ins/common/file-dicom.c b/plug-ins/common/file-dicom.c
index 4b51a789bc..ad6abfa032 100644
--- a/plug-ins/common/file-dicom.c
+++ b/plug-ins/common/file-dicom.c
@@ -841,8 +841,7 @@ dicom_add_element (GSList      *elements,
 
   element->group_word     = group_word;
   element->element_word   = element_word;
-  strncpy (element->value_rep, value_rep, sizeof (element->value_rep) - 1);
-  element->value_rep[sizeof (element->value_rep) - 1] = '\0';
+  g_strlcpy (element->value_rep, value_rep, sizeof (element->value_rep));
   element->element_length = element_length;
   element->value          = value;
 
@@ -1063,8 +1062,7 @@ dicom_get_elements_list (gint32 image_ID)
                   guint16 element_word = 0;
 
                   /* sacrificial buffer */
-                  strncpy (buf, parasites[i], sizeof (buf) - 1);
-                  buf[sizeof (buf) - 1] = '\0';
+                  g_strlcpy (buf, parasites[i], sizeof (buf));
 
                   /* buf should now hold a string of the form
                    * dcm/XXXX-XXXX-AA where XXXX are Hex values for
@@ -1107,10 +1105,7 @@ dicom_get_elements_list (gint32 image_ID)
 
                   /* and lastly, the VR */
                   if (ptr1)
-                    {
-                      strncpy (value_rep, ptr1, sizeof (value_rep) - 1);
-                      value_rep[sizeof (value_rep) - 1] = '\0';
-                    }
+                    g_strlcpy (value_rep, ptr1, sizeof (value_rep));
 
                   /*
                    * If all went according to plan, we should be able
diff --git a/plug-ins/common/file-gbr.c b/plug-ins/common/file-gbr.c
index 80d87b5f7f..91a8de05b3 100644
--- a/plug-ins/common/file-gbr.c
+++ b/plug-ins/common/file-gbr.c
@@ -220,11 +220,10 @@ gbr_save (GimpProcedure        *procedure,
                                           "gimp-brush-name");
       if (parasite)
         {
-          strncpy (info.description,
-                   gimp_parasite_data (parasite),
-                   MIN (sizeof (info.description),
-                        gimp_parasite_data_size (parasite)));
-          info.description[sizeof (info.description) - 1] = '\0';
+          g_strlcpy (info.description,
+                     gimp_parasite_data (parasite),
+                     MIN (sizeof (info.description),
+                          gimp_parasite_data_size (parasite)));
 
           gimp_parasite_free (parasite);
         }
@@ -236,10 +235,7 @@ gbr_save (GimpProcedure        *procedure,
             name[strlen (name) - 4] = '\0';
 
           if (strlen (name))
-            {
-              strncpy (info.description, name, sizeof (info.description));
-              info.description[sizeof (info.description) - 1] = '\0';
-            }
+            g_strlcpy (info.description, name, sizeof (info.description));
 
           g_free (name);
         }
@@ -261,10 +257,9 @@ gbr_save (GimpProcedure        *procedure,
 
     case GIMP_RUN_NONINTERACTIVE:
       info.spacing = g_value_get_int (gimp_value_array_index (args, 0));
-      strncpy (info.description,
-               g_value_get_string (gimp_value_array_index (args, 1)),
-               sizeof (info.description));
-      info.description[sizeof (info.description) - 1] = '\0';
+      g_strlcpy (info.description,
+                 g_value_get_string (gimp_value_array_index (args, 1)),
+                 sizeof (info.description));
       break;
 
     default:
@@ -389,7 +384,6 @@ static void
 entry_callback (GtkWidget *widget,
                 gpointer   data)
 {
-  strncpy (info.description, gtk_entry_get_text (GTK_ENTRY (widget)),
-           sizeof (info.description));
-  info.description[sizeof (info.description) - 1] = '\0';
+  g_strlcpy (info.description, gtk_entry_get_text (GTK_ENTRY (widget)),
+             sizeof (info.description));
 }
diff --git a/plug-ins/common/file-gif-load.c b/plug-ins/common/file-gif-load.c
index e4702f410a..bbc0b41508 100644
--- a/plug-ins/common/file-gif-load.c
+++ b/plug-ins/common/file-gif-load.c
@@ -378,8 +378,7 @@ load_image (const gchar  *filename,
       return -1;
     }
 
-  strncpy (version, (gchar *) buf + 3, 3);
-  version[3] = '\0';
+  g_strlcpy (version, (gchar *) buf + 3, 3);
 
   if ((strcmp (version, "87a") != 0) && (strcmp (version, "89a") != 0))
     {
diff --git a/plug-ins/common/file-gih.c b/plug-ins/common/file-gih.c
index b5949b1e3a..47b2f129b7 100644
--- a/plug-ins/common/file-gih.c
+++ b/plug-ins/common/file-gih.c
@@ -312,11 +312,10 @@ gih_save (GimpProcedure        *procedure,
                                           "gimp-brush-pipe-name");
       if (parasite)
         {
-          strncpy (info.description,
-                   gimp_parasite_data (parasite),
-                   MIN (sizeof (info.description),
-                        gimp_parasite_data_size (parasite)));
-          info.description[sizeof (info.description) - 1] = '\0';
+          g_strlcpy (info.description,
+                     gimp_parasite_data (parasite),
+                     MIN (sizeof (info.description),
+                          gimp_parasite_data_size (parasite)));
 
           gimp_parasite_free (parasite);
         }
@@ -328,10 +327,7 @@ gih_save (GimpProcedure        *procedure,
             name[strlen (name) - 4] = '\0';
 
           if (strlen (name))
-            {
-              strncpy (info.description, name, sizeof (info.description));
-              info.description[sizeof (info.description) - 1] = '\0';
-            }
+            g_strlcpy (info.description, name, sizeof (info.description));
 
           g_free (name);
         }
@@ -385,10 +381,9 @@ gih_save (GimpProcedure        *procedure,
 
     case GIMP_RUN_NONINTERACTIVE:
       info.spacing = g_value_get_int (gimp_value_array_index (args, 0));
-      strncpy (info.description,
-               g_value_get_string (gimp_value_array_index (args, 1)),
-               sizeof (info.description));
-      info.description[sizeof (info.description) - 1] = '\0';
+      g_strlcpy (info.description,
+                 g_value_get_string (gimp_value_array_index (args, 1)),
+                 sizeof (info.description));
 
       gihparams.cellwidth  = g_value_get_int (gimp_value_array_index (args, 2));
       gihparams.cellheight = g_value_get_int (gimp_value_array_index (args, 3));
@@ -567,11 +562,8 @@ entry_callback (GtkWidget *widget,
                 gpointer   data)
 {
   if (data == info.description)
-    {
-      strncpy (info.description, gtk_entry_get_text (GTK_ENTRY (widget)),
+    g_strlcpy (info.description, gtk_entry_get_text (GTK_ENTRY (widget)),
                sizeof (info.description));
-      info.description[sizeof (info.description) - 1]  = 0;
-    }
 }
 
 static void
diff --git a/plug-ins/common/file-html-table.c b/plug-ins/common/file-html-table.c
index a596b252f1..c37005411d 100644
--- a/plug-ins/common/file-html-table.c
+++ b/plug-ins/common/file-html-table.c
@@ -742,5 +742,5 @@ static void
 entry_changed_callback (GtkEntry *entry,
                         gchar    *string)
 {
-  strncpy (string, gtk_entry_get_text (entry), 255);
+  g_strlcpy (string, gtk_entry_get_text (entry), 256);
 }
diff --git a/plug-ins/common/file-pat.c b/plug-ins/common/file-pat.c
index 223648e45a..2224abfa09 100644
--- a/plug-ins/common/file-pat.c
+++ b/plug-ins/common/file-pat.c
@@ -185,11 +185,10 @@ pat_save (GimpProcedure        *procedure,
                                           "gimp-pattern-name");
       if (parasite)
         {
-          strncpy (description,
-                   gimp_parasite_data (parasite),
-                   MIN (sizeof (description),
-                        gimp_parasite_data_size (parasite)));
-          description[sizeof (description) - 1] = '\0';
+          g_strlcpy (description,
+                     gimp_parasite_data (parasite),
+                     MIN (sizeof (description),
+                          gimp_parasite_data_size (parasite)));
 
           gimp_parasite_free (parasite);
         }
@@ -201,10 +200,7 @@ pat_save (GimpProcedure        *procedure,
             name[strlen (name) - 4] = '\0';
 
           if (strlen (name))
-            {
-              strncpy (description, name, sizeof (description));
-              description[sizeof (description) - 1] = '\0';
-            }
+            g_strlcpy (description, name, sizeof (description));
 
           g_free (name);
         }
@@ -225,10 +221,9 @@ pat_save (GimpProcedure        *procedure,
       break;
 
     case GIMP_RUN_NONINTERACTIVE:
-      strncpy (description,
-               g_value_get_string (gimp_value_array_index (args, 0)),
-               sizeof (description));
-      description[sizeof (description) - 1] = '\0';
+      g_strlcpy (description,
+                 g_value_get_string (gimp_value_array_index (args, 0)),
+                 sizeof (description));
       break;
 
     default:
@@ -326,11 +321,8 @@ save_dialog (void)
   run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
 
   if (run)
-    {
-      strncpy (description, gtk_entry_get_text (GTK_ENTRY (entry)),
+    g_strlcpy (description, gtk_entry_get_text (GTK_ENTRY (entry)),
                sizeof (description));
-      description[sizeof (description) - 1] = '\0';
-    }
 
   gtk_widget_destroy (dialog);
 
diff --git a/plug-ins/common/file-ps.c b/plug-ins/common/file-ps.c
index 4ddcce43b8..f5f4e7bb6a 100644
--- a/plug-ins/common/file-ps.c
+++ b/plug-ins/common/file-ps.c
@@ -880,7 +880,7 @@ run (const gchar      *name,
           plvals.resolution = size / 4;
           plvals.width      = size;
           plvals.height     = size;
-          strncpy (plvals.pages, "1", sizeof (plvals.pages) - 1);
+          g_strlcpy (plvals.pages, "1", sizeof (plvals.pages));
 
           check_load_vals ();
           image_ID = load_image (param[0].data.d_string, &error);
@@ -1009,8 +1009,8 @@ run (const gchar      *name,
           plvals.height     = param[2].data.d_int32;
           plvals.use_bbox   = param[3].data.d_int32;
           if (param[4].data.d_string != NULL)
-            strncpy (plvals.pages, param[4].data.d_string,
-                     sizeof (plvals.pages));
+            g_strlcpy (plvals.pages, param[4].data.d_string,
+                       sizeof (plvals.pages));
           else
             plvals.pages[0] = '\0';
           plvals.pages[sizeof (plvals.pages) - 1] = '\0';
@@ -1316,7 +1316,7 @@ check_load_vals (void)
     plvals.height = 2;
   plvals.use_bbox = (plvals.use_bbox != 0);
   if (plvals.pages[0] == '\0')
-    strncpy (plvals.pages, "1-99", sizeof (plvals.pages) - 1);
+    g_strlcpy (plvals.pages, "1-99", sizeof (plvals.pages));
   if ((plvals.pnm_type < 4) || (plvals.pnm_type > 7))
     plvals.pnm_type = 6;
   if (   (plvals.textalpha != 1) && (plvals.textalpha != 2)
@@ -1359,8 +1359,7 @@ page_in_list (gchar *list,
   if ((list == NULL) || (*list == '\0'))
     return 1;
 
-  strncpy (tmplist, list, STR_LENGTH);
-  tmplist[STR_LENGTH-1] = '\0';
+  g_strlcpy (tmplist, list, STR_LENGTH);
 
   c0 = c1 = tmplist;
   while (*c1)    /* Remove all whitespace and break on unsupported characters */
@@ -3587,8 +3586,7 @@ load_dialog (const gchar *filename)
           range = gimp_page_selector_get_selected_range (GIMP_PAGE_SELECTOR (selector));
         }
 
-      strncpy (plvals.pages, range, sizeof (plvals.pages) - 1);
-      plvals.pages[strlen (range)] = '\0';
+      g_strlcpy (plvals.pages, range, sizeof (plvals.pages));
 
       ps_pagemode = gimp_page_selector_get_target (GIMP_PAGE_SELECTOR (selector));
     }
@@ -3598,7 +3596,7 @@ load_dialog (const gchar *filename)
     }
   else
     {
-      strncpy (plvals.pages, "1", sizeof (plvals.pages) - 1);
+      g_strlcpy (plvals.pages, "1", sizeof (plvals.pages));
       ps_pagemode = GIMP_PAGE_SELECTOR_TARGET_IMAGES;
     }
 
@@ -3611,10 +3609,8 @@ static void
 load_pages_entry_callback (GtkWidget *widget,
                            gpointer   data)
 {
-  gsize nelem = sizeof (plvals.pages);
-
-  strncpy (plvals.pages, gtk_entry_get_text (GTK_ENTRY (widget)), nelem);
-  plvals.pages[nelem-1] = '\0';
+  g_strlcpy (plvals.pages, gtk_entry_get_text (GTK_ENTRY (widget)),
+             sizeof (plvals.pages));
 }
 
 
diff --git a/plug-ins/common/file-xbm.c b/plug-ins/common/file-xbm.c
index 3159ce1a8e..40c3dd1193 100644
--- a/plug-ins/common/file-xbm.c
+++ b/plug-ins/common/file-xbm.c
@@ -228,7 +228,7 @@ init_prefix (const gchar *filename)
       else
         len = MAX_PREFIX;
 
-      strncpy (xsvals.prefix, prefix, len);
+      g_strlcpy (xsvals.prefix, prefix, len);
       g_free (prefix);
     }
 
@@ -255,7 +255,7 @@ run (const gchar      *name,
   INIT_I18N ();
   gegl_init (NULL, NULL);
 
-  strncpy (xsvals.comment, "Created with GIMP", MAX_COMMENT);
+  g_strlcpy (xsvals.comment, "Created with GIMP", MAX_COMMENT);
 
   run_mode = param[0].data.d_int32;
 
@@ -333,11 +333,8 @@ run (const gchar      *name,
               gint i = 5;
 
               if (nparams > i)
-                {
-                  memset (xsvals.comment, 0, sizeof (xsvals.comment));
-                  strncpy (xsvals.comment, param[i].data.d_string,
+                g_strlcpy (xsvals.comment, param[i].data.d_string,
                            MAX_COMMENT);
-                }
 
               i ++;
               if (nparams > i)
@@ -356,19 +353,15 @@ run (const gchar      *name,
 
               i ++;
               if (nparams > i)
-                {
-                  memset (xsvals.prefix, 0, sizeof (xsvals.prefix));
-                  strncpy (xsvals.prefix, param[i].data.d_string,
+                g_strlcpy (xsvals.prefix, param[i].data.d_string,
                            MAX_PREFIX);
-                }
 
               i += 2;
               if (nparams > i)
                 {
                   xsvals.write_mask = param[i - 1].data.d_int32;
-                  memset (xsvals.mask_ext, 0, sizeof (xsvals.mask_ext));
-                  strncpy (xsvals.mask_ext, param[i].data.d_string,
-                           MAX_MASK_EXT);
+                  g_strlcpy (xsvals.mask_ext, param[i].data.d_string,
+                             MAX_MASK_EXT);
                 }
 
               i ++;
@@ -391,9 +384,9 @@ run (const gchar      *name,
             {
               gint size = gimp_parasite_data_size (parasite);
 
-              strncpy (xsvals.comment,
-                       gimp_parasite_data (parasite), MIN (size, MAX_COMMENT));
-              xsvals.comment[MIN (size, MAX_COMMENT) + 1] = 0;
+              g_strlcpy (xsvals.comment,
+                         gimp_parasite_data (parasite),
+                         MIN (size, MAX_COMMENT));
 
               gimp_parasite_free (parasite);
             }
@@ -1418,9 +1411,8 @@ static void
 comment_entry_callback (GtkWidget *widget,
                         gpointer   data)
 {
-  memset (xsvals.comment, 0, sizeof (xsvals.comment));
-  strncpy (xsvals.comment,
-           gtk_entry_get_text (GTK_ENTRY (widget)), MAX_COMMENT);
+  g_strlcpy (xsvals.comment,
+             gtk_entry_get_text (GTK_ENTRY (widget)), MAX_COMMENT);
 }
 #endif
 
@@ -1428,16 +1420,14 @@ static void
 prefix_entry_callback (GtkWidget *widget,
                        gpointer   data)
 {
-  memset (xsvals.prefix, 0, sizeof (xsvals.prefix));
-  strncpy (xsvals.prefix,
-           gtk_entry_get_text (GTK_ENTRY (widget)), MAX_PREFIX);
+  g_strlcpy (xsvals.prefix,
+             gtk_entry_get_text (GTK_ENTRY (widget)), MAX_PREFIX);
 }
 
 static void
 mask_ext_entry_callback (GtkWidget *widget,
                        gpointer   data)
 {
-  memset (xsvals.mask_ext, 0, sizeof (xsvals.mask_ext));
-  strncpy (xsvals.mask_ext,
-           gtk_entry_get_text (GTK_ENTRY (widget)), MAX_MASK_EXT);
+  g_strlcpy (xsvals.mask_ext,
+             gtk_entry_get_text (GTK_ENTRY (widget)), MAX_MASK_EXT);
 }
diff --git a/plug-ins/common/plugin-browser.c b/plug-ins/common/plugin-browser.c
index bde6413e52..37143130e2 100644
--- a/plug-ins/common/plugin-browser.c
+++ b/plug-ins/common/plugin-browser.c
@@ -491,8 +491,7 @@ browser_search (GimpBrowser   *gimp_browser,
 
               if ((utf8 = g_locale_to_utf8 (xtimestr, -1, NULL, NULL, NULL)))
                 {
-                  strncpy (xtimestr, utf8, sizeof (xtimestr));
-                  xtimestr[sizeof (xtimestr) - 1] = 0;
+                  g_strlcpy (xtimestr, utf8, sizeof (xtimestr));
                   g_free (utf8);
                 }
             }
diff --git a/plug-ins/common/qbist.c b/plug-ins/common/qbist.c
index 5f1b42fa1d..09e0c365ba 100644
--- a/plug-ins/common/qbist.c
+++ b/plug-ins/common/qbist.c
@@ -734,7 +734,7 @@ dialog_load (GtkWidget *widget,
     {
       gchar *name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
 
-      strncpy (qbist_info.path, name, PATH_MAX - 1);
+      g_strlcpy (qbist_info.path, name, PATH_MAX);
       load_data (qbist_info.path);
 
       g_free (name);
@@ -779,7 +779,7 @@ dialog_save (GtkWidget *widget,
     {
       gchar *name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
 
-      strncpy (qbist_info.path, name, PATH_MAX - 1);
+      g_strlcpy (qbist_info.path, name, PATH_MAX);
       save_data (qbist_info.path);
 
       g_free (name);
diff --git a/plug-ins/common/web-page.c b/plug-ins/common/web-page.c
index 8804ed6a5b..f87bedd6a9 100644
--- a/plug-ins/common/web-page.c
+++ b/plug-ins/common/web-page.c
@@ -185,8 +185,7 @@ run (const gchar      *name,
 
           if (strlen (webpagevals.url) < MAX_URL_LEN)
             {
-              strncpy (save.url, webpagevals.url, MAX_URL_LEN);
-              save.url[MAX_URL_LEN - 1] = 0;
+              g_strlcpy (save.url, webpagevals.url, MAX_URL_LEN);
             }
           else
             {
diff --git a/plug-ins/file-fits/fits-io.c b/plug-ins/file-fits/fits-io.c
index 9d429b7dc4..fe524d2b50 100644
--- a/plug-ins/file-fits/fits-io.c
+++ b/plug-ins/file-fits/fits-io.c
@@ -508,10 +508,7 @@ static void
 fits_set_error (const gchar *errmsg)
 {
   if (fits_n_error < FITS_MAX_ERROR)
-    {
-      strncpy (fits_error[fits_n_error], errmsg, FITS_ERROR_LENGTH);
-      fits_error[fits_n_error++][FITS_ERROR_LENGTH-1] = '\0';
-    }
+    g_strlcpy (fits_error[fits_n_error], errmsg, FITS_ERROR_LENGTH);
 }
 
 
diff --git a/plug-ins/gradient-flare/gradient-flare.c b/plug-ins/gradient-flare/gradient-flare.c
index 0747938a3d..16234660ce 100644
--- a/plug-ins/gradient-flare/gradient-flare.c
+++ b/plug-ins/gradient-flare/gradient-flare.c
@@ -1576,8 +1576,7 @@ static void
 gflare_name_copy (gchar       *dest,
                   const gchar *src)
 {
-  strncpy (dest, src, GFLARE_NAME_MAX - 1);
-  dest[GFLARE_NAME_MAX - 1] = '\0';
+  g_strlcpy (dest, src, GFLARE_NAME_MAX);
 }
 
 /*************************************************************************/
@@ -4708,8 +4707,7 @@ static void
 gradient_name_copy (gchar       *dest,
                     const gchar *src)
 {
-  strncpy (dest, src, GRADIENT_NAME_MAX - 1);
-  dest[GRADIENT_NAME_MAX - 1] = '\0';
+  g_strlcpy (dest, src, GRADIENT_NAME_MAX);
 }
 
 /*
@@ -5063,8 +5061,7 @@ gradient_cache_lookup (const gchar *name,
       while (gradient_cache_count >= GRADIENT_CACHE_SIZE)
         gradient_cache_zorch();
       ci = g_new (GradientCacheItem, 1);
-      strncpy (ci->name, name, GRADIENT_NAME_MAX - 1);
-      ci->name[GRADIENT_NAME_MAX - 1] = '\0';
+      g_strlcpy (ci->name, name, GRADIENT_NAME_MAX);
       ci->next = gradient_cache_head;
       ci->prev = NULL;
       if (gradient_cache_head)
diff --git a/plug-ins/screenshot/screenshot-win32.c b/plug-ins/screenshot/screenshot-win32.c
index a72db45eee..afbe7a081c 100644
--- a/plug-ins/screenshot/screenshot-win32.c
+++ b/plug-ins/screenshot/screenshot-win32.c
@@ -386,7 +386,7 @@ formatWindowsError (char *buffer,
     (LPTSTR) &lpMsgBuf, 0, NULL );
 
   /* Copy to the buffer */
-  strncpy(buffer, lpMsgBuf, buf_size - 1);
+  g_strlcpy (buffer, lpMsgBuf, buf_size);
 
   LocalFree(lpMsgBuf);
 }
diff --git a/plug-ins/script-fu/script-fu-server.c b/plug-ins/script-fu/script-fu-server.c
index 7341dd7c9e..5272646230 100644
--- a/plug-ins/script-fu/script-fu-server.c
+++ b/plug-ins/script-fu/script-fu-server.c
@@ -370,7 +370,7 @@ script_fu_server_listen (gint timeout)
       /*  Associate the client address with the socket  */
 
       /* If all else fails ... */
-      strncpy (clientname, "(error during host address lookup)", NI_MAXHOST-1);
+      g_strlcpy (clientname, "(error during host address lookup)", NI_MAXHOST);
 
       /* Lookup address */
       (void) getnameinfo (&(client.sa), size, clientname, sizeof (clientname),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]