Avoid unfounded warnings from GCC 7.2.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 24 Sep 2017 02:44:48 +0000 (19:44 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 24 Sep 2017 02:44:48 +0000 (19:44 -0700)
GCC thinks that these printf formats can produce output longer than the
buffer that is available for them.  I think that it is wrong, but it is
easy enough to use larger (or variable-length) buffers, so this commit
does that.

src/data/sys-file-writer.c
src/language/stats/descriptives.c

index 7f0c8c056abb1d0f39bb564bd62ae5d2f4f4d17a..df5108e2a062758ae79d561f5d1ee51b29a1c152 100644 (file)
@@ -365,8 +365,6 @@ write_header (struct sfm_writer *w, const struct dictionary *d)
 {
   const char *dict_encoding = dict_get_encoding (d);
   char prod_name[61];
-  char creation_date[10];
-  char creation_time[9];
   const char *file_label;
   struct variable *weight;
 
@@ -409,10 +407,11 @@ write_header (struct sfm_writer *w, const struct dictionary *d)
   write_float (w, COMPRESSION_BIAS);
 
   /* Creation date and time. */
+  char *creation_date, *creation_time;
   if (time (&t) == (time_t) -1)
     {
-      strcpy (creation_date, "01 Jan 70");
-      strcpy (creation_time, "00:00:00");
+      creation_date = xstrdup ("01 Jan 70");
+      creation_time = xstrdup ( "00:00:00");
     }
   else
     {
@@ -429,13 +428,14 @@ write_header (struct sfm_writer *w, const struct dictionary *d)
       int min = rerange (tmp->tm_min + 1);
       int sec = rerange (tmp->tm_sec + 1);
 
-      snprintf (creation_date, sizeof creation_date,
-                "%02d %s %02d", day, month_name[mon - 1], year);
-      snprintf (creation_time, sizeof creation_time,
-                "%02d:%02d:%02d", hour - 1, min - 1, sec - 1);
+      creation_date = xasprintf ("%02d %s %02d",
+                                 day, month_name[mon - 1], year);
+      creation_time = xasprintf ("%02d:%02d:%02d", hour - 1, min - 1, sec - 1);
     }
   write_utf8_string (w, dict_encoding, creation_date, 9);
   write_utf8_string (w, dict_encoding, creation_time, 8);
+  free (creation_time);
+  free (creation_date);
 
   /* File label. */
   file_label = dict_get_label (d);
index 7182049a6668850f02ffc28c08c9f1d58cf7773e..11a9f7f31e50fad3bf8fe540a046c9af57eaadd4 100644 (file)
@@ -558,7 +558,7 @@ generate_z_varname (const struct dictionary *dict, struct dsc_proc *dsc,
   /* Generate a synthetic name. */
   for (;;)
     {
-      char name[8];
+      char name[16];
 
       (*z_cnt)++;