por-file-reader: Use xasprintf() to avoid need for careful buffer sizing.
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 2 Jan 2019 22:26:24 +0000 (14:26 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 2 Jan 2019 22:50:14 +0000 (14:50 -0800)
GCC 4.9 complained about this, saying that the output could exceed the
buffer size.  It doesn't seem worth arguing with it.

src/data/por-file-reader.c

index 1dcbeac71c540eb81c9654d619b575f85367316b..343615a826fcecb70f6e013b101b4cba1c6f36b1 100644 (file)
@@ -43,7 +43,6 @@
 #include "libpspp/pool.h"
 #include "libpspp/str.h"
 
-#include "gl/intprops.h"
 #include "gl/minmax.h"
 #include "gl/xalloc.h"
 #include "gl/xmemdup0.h"
@@ -729,9 +728,9 @@ read_variables (struct pfm_reader *r, struct dictionary *dict)
           unsigned long int i;
           for (i = 1; ; i++)
             {
-              char try_name[8 + 1 + INT_STRLEN_BOUND (i) + 1];
-              sprintf (try_name, "%s_%lu", name, i);
+              char *try_name = xasprintf ("%s_%lu", name, i);
               v = dict_create_var (dict, try_name, width);
+              free (try_name);
               if (v != NULL)
                 break;
             }