From 54b3aa8432383287c75b9baf954b7bf887126a0c Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 3 Mar 2023 16:43:59 -0800 Subject: [PATCH] dataset: Before deleting variables, make sure new values are added. This fixes a crash reported privately by knassen(at)chartermi.net. --- src/data/dataset.c | 6 ++++++ tests/language/commands/delete-variables.at | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/data/dataset.c b/src/data/dataset.c index 6ade4b24c9..9503521207 100644 --- a/src/data/dataset.c +++ b/src/data/dataset.c @@ -354,6 +354,12 @@ dataset_delete_vars (struct dataset *ds, struct variable **vars, size_t n) assert (!proc_has_transformations (ds)); assert (n < dict_get_n_vars (ds->dict)); + caseinit_mark_for_init (ds->caseinit, ds->dict); + ds->source = caseinit_translate_casereader_to_init_vars ( + ds->caseinit, dict_get_proto (ds->dict), ds->source); + caseinit_clear (ds->caseinit); + caseinit_mark_as_preinited (ds->caseinit, ds->dict); + dict_delete_vars (ds->dict, vars, n); ds->source = case_map_create_input_translator ( case_map_to_compact_dict (ds->dict, 0), ds->source); diff --git a/tests/language/commands/delete-variables.at b/tests/language/commands/delete-variables.at index 172e37b69c..a679c21fee 100644 --- a/tests/language/commands/delete-variables.at +++ b/tests/language/commands/delete-variables.at @@ -87,6 +87,25 @@ ID,respondent_city_of_birth,respondent_name,respondent_year_of_birth,varlist ]) AT_CLEANUP +dnl Checks for regression against a crash reported privately by +dnl knassen(at)chartermi.net on March 1, 2023. +AT_SETUP([DELETE VARIABLES crash 2]) +AT_DATA([delete-variables.sps], [dnl +DATA LIST LIST NOTABLE /foo (A5). +STRING bar (A8). +DELETE VARIABLES foo. +LIST. +BEGIN DATA. +asdf +END DATA. +]) +AT_CHECK([pspp -O format=csv delete-variables.sps], [0], [dnl +Table: Data List +bar + +]) +AT_CLEANUP + AT_SETUP([DELETE VARIABLES syntax errors]) AT_DATA([delete-variables.sps], [dnl DATA LIST LIST NOTABLE /x y z. -- 2.30.2