dictionary: Limit split file variables to 8, for compatibility.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 6 Aug 2022 19:31:40 +0000 (12:31 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 7 Aug 2022 16:53:13 +0000 (09:53 -0700)
src/data/dictionary.c
src/data/dictionary.h
src/language/dictionary/split-file.c
tests/language/dictionary/split-file.at

index 750d7858004d86d9bac70da1601fe94cd539ab29..c13321c7827bb2cd877c598d834f5bbc2a341c6e 100644 (file)
@@ -384,12 +384,15 @@ dict_unset_split_var (struct dictionary *d, struct variable *v, bool skip_callba
 }
 
 
-/* Sets N split vars SPLIT in dictionary D. */
+/* Sets N split vars SPLIT in dictionary D.  N is silently capped to a maximum
+   of MAX_SPLITS. */
 static void
 dict_set_split_vars__ (struct dictionary *d,
                        struct variable *const *split, size_t n,
                        enum split_type type, bool skip_callbacks)
 {
+  if (n > MAX_SPLITS)
+    n = MAX_SPLITS;
   assert (n == 0 || split != NULL);
 
   d->n_splits = n;
index 050b4a8c4dff01febadf5f7896dd40c002d9066f..47317a22cbc23e61a56de8602b09123daea92499 100644 (file)
@@ -132,6 +132,7 @@ enum split_type
     SPLIT_SEPARATE,             /* Produce separate output for each split. */
     SPLIT_LAYERED,              /* Output splits in same table.  */
   };
+#define MAX_SPLITS 8
 const struct variable *const *dict_get_split_vars (const struct dictionary *);
 size_t dict_get_n_splits (const struct dictionary *);
 enum split_type dict_get_split_type (const struct dictionary *);
index 8b4c8783371a8d165a1243c2896a9618f542f557..8a134e1e769eca5562e57e31febb49b9c29b03d0 100644 (file)
@@ -58,6 +58,14 @@ cmd_split_file (struct lexer *lexer, struct dataset *ds)
       if (!parse_variables (lexer, dataset_dict (ds), &v, &n, PV_NO_DUPLICATE))
        return CMD_CASCADING_FAILURE;
 
+      if (n > MAX_SPLITS)
+        {
+          verify (MAX_SPLITS == 8);
+          msg (SE, _("At most 8 split variables may be specified."));
+          free (v);
+          return CMD_CASCADING_FAILURE;
+        }
+
       dict_set_split_vars (dataset_dict (ds), v, n, type);
       free (v);
     }
index 674bd6ff05eb339ac2032f1b52fa60d6aeb52735..e9ce7cba6fa3d77b7055955c4c760776585f5e57 100644 (file)
@@ -70,10 +70,6 @@ X,Y
 ])
 AT_CLEANUP
 
-
-
-
-
 AT_SETUP([SPLIT FILE  - vs procedures])
 AT_DATA([split-file.sps], [dnl
 
@@ -136,3 +132,11 @@ finish.
 AT_CHECK([pspp -O format=csv split-file.sps], [0],[ignore])
 
 AT_CLEANUP
+
+AT_SETUP([SPLIT FILE - split variable limit])
+AT_DATA([split-file.sps], [dnl
+DATA LIST LIST NOTABLE /V1 TO V9.
+SPLIT FILE BY V1 TO V9.
+])
+AT_CHECK([pspp split-file.sps])
+AT_CLEANUP