DATA LIST: Fix crash inside LOOP.
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 18 Apr 2023 15:45:48 +0000 (08:45 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 18 Apr 2023 15:45:59 +0000 (08:45 -0700)
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 <youngseok.main@gmail.com>
Reported-at: https://lists.gnu.org/archive/html/bug-gnu-pspp/2023-04/msg00002.html.

src/language/command.c
src/language/command.def
tests/language/commands/data-list.at

index 0c77337695691b5ce6a5316bfe5b2f938261ffd1..97e01fca5a28aaf517d89470a97b4486e5ab7026 100644 (file)
@@ -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 ();
         }
index 24ce236f5690874d4210a9c19313d7311536444d..f5cb1611a170c55090f93b4f5295decbb1caf22b 100644 (file)
@@ -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)
index 052481f1c5fd0b63bf1f85b3cdaa62901d0f149a..3c3ab13ef9af3757debfd13ec0dfcce1e34fe154 100644 (file)
@@ -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