MATRIX DATA: Fix crash when duplicate variables are specified
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 1 May 2017 19:02:22 +0000 (21:02 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Mon, 1 May 2017 19:02:22 +0000 (21:02 +0200)
src/language/data-io/matrix-data.c
src/language/lexer/variable-parser.c
tests/language/data-io/matrix-data.at

index fb214fd644a399c517652e854ad2c2ba31be804b..db7c9d05bdd29941640027151b89daabc1965828 100644 (file)
@@ -302,6 +302,8 @@ cmd_matrix (struct lexer *lexer, struct dataset *ds)
 
   mformat.triangle = LOWER;
   mformat.diagonal = DIAGONAL;
+  mformat.n_split_vars = 0;
+  mformat.split_vars = NULL;
 
   dict = (in_input_program ()
           ? dataset_dict (ds)
@@ -324,7 +326,7 @@ cmd_matrix (struct lexer *lexer, struct dataset *ds)
 
   lex_match (lexer, T_EQUALS);
 
-  if (! parse_mixed_vars (lexer, dict, &names, &n_names, 0))
+  if (! parse_mixed_vars (lexer, dict, &names, &n_names, PV_NO_DUPLICATE))
     {
       int i;
       for (i = 0; i < n_names; ++i)
@@ -475,6 +477,7 @@ cmd_matrix (struct lexer *lexer, struct dataset *ds)
 
   fh_unref (fh);
   free (encoding);
+  free (mformat.split_vars);
 
   return CMD_DATA_LIST;
 
@@ -484,6 +487,7 @@ cmd_matrix (struct lexer *lexer, struct dataset *ds)
     dict_destroy (dict);
   fh_unref (fh);
   free (encoding);
+  free (mformat.split_vars);
   return CMD_CASCADING_FAILURE;
 }
 
index 9819acbbc192aff766a53bf337616ed0528a6014..b91c038ac9080f6404cddbfe08344c184394fd57 100644 (file)
@@ -607,7 +607,6 @@ parse_mixed_vars (struct lexer *lexer, const struct dictionary *dict,
 
   assert (names != NULL);
   assert (nnames != NULL);
-  assert ((pv_opts & ~PV_APPEND) == 0);
 
   if (!(pv_opts & PV_APPEND))
     {
@@ -621,7 +620,7 @@ parse_mixed_vars (struct lexer *lexer, const struct dictionary *dict,
          struct variable **v;
          size_t nv;
 
-         if (!parse_variables (lexer, dict, &v, &nv, PV_NONE))
+         if (!parse_variables (lexer, dict, &v, &nv, pv_opts))
            goto fail;
          *names = xnrealloc (*names, *nnames + nv, sizeof **names);
          for (i = 0; i < nv; i++)
@@ -629,7 +628,7 @@ parse_mixed_vars (struct lexer *lexer, const struct dictionary *dict,
          free (v);
          *nnames += nv;
        }
-      else if (!parse_DATA_LIST_vars (lexer, dict, names, nnames, PV_APPEND))
+      else if (!parse_DATA_LIST_vars (lexer, dict, names, nnames, PV_APPEND | pv_opts))
        goto fail;
     }
   if (*nnames == 0)
index 3047b1f57f55e9180a1d87ee7da0a0f4e1f27713..727470cefee6319e97893770b5b1dbe6dee073d7 100644 (file)
@@ -242,3 +242,36 @@ s1,s2,ROWTYPE_,VARNAME_,var01,var02,var03
 ])
 
 AT_CLEANUP
+
+
+
+
+AT_SETUP([Matrix data duplicate variable])
+
+dnl Negative test to check for sane behaviour in the face of bad syntax
+AT_DATA([matrix-data.pspp], [dnl
+set decimal = dot .
+matrix data
+    variables = s1 s1 rowtype_  var01 var02 var03
+    /split=s1.
+
+begin data
+0   mean     21.4  5.0  72.9
+0   sd       6.5   1.6  22.8
+0   n        106   106  106
+0   corr     1
+0   corr    .41  1
+0   corr    -.16  -.22  1
+end data .
+
+list.
+])
+
+
+AT_CHECK([pspp -O format=csv matrix-data.pspp], [1], [dnl
+matrix-data.pspp:3: error: MATRIX DATA: Variable s1 appears twice in variable list.
+
+matrix-data.pspp:6: error: Stopping syntax file processing here to avoid a cascade of dependent command failures.
+])
+
+AT_CLEANUP