From 24cbabb1547682037cda854b46c2e4bdf87a2c8a Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 6 Aug 2022 12:31:40 -0700 Subject: [PATCH] dictionary: Limit split file variables to 8, for compatibility. --- src/data/dictionary.c | 5 ++++- src/data/dictionary.h | 1 + src/language/dictionary/split-file.c | 8 ++++++++ tests/language/dictionary/split-file.at | 12 ++++++++---- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 750d785800..c13321c782 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -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; diff --git a/src/data/dictionary.h b/src/data/dictionary.h index 050b4a8c4d..47317a22cb 100644 --- a/src/data/dictionary.h +++ b/src/data/dictionary.h @@ -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 *); diff --git a/src/language/dictionary/split-file.c b/src/language/dictionary/split-file.c index 8b4c878337..8a134e1e76 100644 --- a/src/language/dictionary/split-file.c +++ b/src/language/dictionary/split-file.c @@ -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); } diff --git a/tests/language/dictionary/split-file.at b/tests/language/dictionary/split-file.at index 674bd6ff05..e9ce7cba6f 100644 --- a/tests/language/dictionary/split-file.at +++ b/tests/language/dictionary/split-file.at @@ -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 -- 2.30.2