matrix-data: Only use as many bytes as necessary to initialize string.
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 2 Jan 2019 22:46:11 +0000 (14:46 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 2 Jan 2019 22:50:14 +0000 (14:50 -0800)
Using strncpy() of a 9-character string to initialize an 8-byte field is
odd and seems likely to have been a mistake, although a harmless one.
This makes the situation seem less odd.

Found by GCC 4.9.

src/language/data-io/matrix-data.c

index 97d14739b3a56ab2b8ef7f1cc38ad137ddf911d4..81e687983c4110aa290d231944f0960d64916119 100644 (file)
@@ -214,7 +214,7 @@ preprocess (struct casereader *casereader0, const struct dictionary *dict, void
       struct ccase *outcase = case_create (proto);
       union value *v = case_data_rw (outcase, mformat->rowtype);
       uint8_t *n = value_str_rw (v, ROWTYPE_WIDTH);
-      strncpy ((char *) n, "N        ", ROWTYPE_WIDTH);
+      memcpy (n, "N       ", ROWTYPE_WIDTH);
       blank_varname_column (outcase, mformat->varname);
       for (col = 0; col < mformat->n_continuous_vars; ++col)
        {