From 469786accf638c29c86c82c579ae163be71f5d20 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 18 Apr 2023 08:45:48 -0700 Subject: [PATCH] DATA LIST: Fix crash inside LOOP. DATA LIST should be allowed inside LOOP if the LOOP is inside INPUT PROGRAM, and disallowed otherwise. The latter behavior was not correct before this commit. Reported-by: Youngseok Choi Reported-at: https://lists.gnu.org/archive/html/bug-gnu-pspp/2023-04/msg00002.html. --- src/language/command.c | 5 +++++ src/language/command.def | 3 ++- tests/language/commands/data-list.at | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/language/command.c b/src/language/command.c index 0c77337695..97e01fca5a 100644 --- a/src/language/command.c +++ b/src/language/command.c @@ -466,6 +466,11 @@ report_state_mismatch (const struct command *command, enum cmd_state state) "%s is not allowed inside DO IF or LOOP."), command->name); + case S_NESTED_INPUT_PROGRAM: + return xasprintf (_("%s is not allowed inside DO IF or LOOP " + "(except inside INPUT PROGRAM)."), + command->name); + default: NOT_REACHED (); } diff --git a/src/language/command.def b/src/language/command.def index 24ce236f56..f5cb1611a1 100644 --- a/src/language/command.def +++ b/src/language/command.def @@ -50,7 +50,8 @@ DEF_CMD (S_ANY, 0, "TITLE", cmd_title) /* Commands that define (or replace) the active dataset. */ DEF_CMD (S_INITIAL | S_DATA, 0, "ADD FILES", cmd_add_files) -DEF_CMD (S_ANY, 0, "DATA LIST", cmd_data_list) +DEF_CMD (S_INITIAL | S_DATA | S_INPUT_PROGRAM | S_FILE_TYPE | S_NESTED_INPUT_PROGRAM, + 0, "DATA LIST", cmd_data_list) DEF_CMD (S_INITIAL | S_DATA, 0, "GET", cmd_get) DEF_CMD (S_INITIAL | S_DATA, 0, "GET DATA", cmd_get_data) DEF_CMD (S_INITIAL | S_DATA, 0, "IMPORT", cmd_import) diff --git a/tests/language/commands/data-list.at b/tests/language/commands/data-list.at index 052481f1c5..3c3ab13ef9 100644 --- a/tests/language/commands/data-list.at +++ b/tests/language/commands/data-list.at @@ -693,3 +693,21 @@ AT_CHECK([pspp data-list.sps -O box=unicode], [0], [dnl ╰────────┴──────┴───────┴──────╯ ]) AT_CLEANUP + +# Checks for a bug where DATA LIST was allowed inside LOOP, which +# cleared the dataset and caused LOOP to assert-fail because its +# transformation stack entry had been popped. +AT_SETUP([DATA LIST inside LOOP]) +AT_DATA([data-list.sps], [dnl +DATA LIST LIST NOTABLE/x y z. +LOOP. +DATA LIST. +END LOOP. +]) +AT_CHECK([pspp data-list.sps], [1], [dnl +data-list.sps:3.1-3.9: error: DATA LIST: DATA LIST is not allowed inside DO IF +or LOOP (except inside INPUT PROGRAM). + 3 | DATA LIST. + | ^~~~~~~~~ +]) +AT_CLEANUP \ No newline at end of file -- 2.30.2