From fb5c914b237698faa7701cca179d4ddbc853ceea Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 9 Apr 2011 19:11:44 -0700 Subject: [PATCH] LIST: Fix crash when SPLIT FILE was used. Thanks to John Darrington for reporting the problem and to Michel Boaventura for reducing the problem to a simple test case. --- src/language/data-io/list.q | 14 +++++------ tests/language/data-io/list.at | 44 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/language/data-io/list.q b/src/language/data-io/list.q index 6bb2bed2..ddc072a4 100644 --- a/src/language/data-io/list.q +++ b/src/language/data-io/list.q @@ -130,13 +130,6 @@ cmd_list (struct lexer *lexer, struct dataset *ds) struct ccase *ccase; struct table *t; - group = casereader_project (group, &sc); - if (cmd.numbering == LST_NUMBERED) - group = casereader_create_arithmetic_sequence (group, 1, 1); - group = casereader_select (group, cmd.first - 1, - (cmd.last != LONG_MAX ? cmd.last - : CASENUMBER_MAX), cmd.step); - ccase = casereader_peek (group, 0); if (ccase != NULL) { @@ -144,6 +137,13 @@ cmd_list (struct lexer *lexer, struct dataset *ds) case_unref (ccase); } + group = casereader_project (group, &sc); + if (cmd.numbering == LST_NUMBERED) + group = casereader_create_arithmetic_sequence (group, 1, 1); + group = casereader_select (group, cmd.first - 1, + (cmd.last != LONG_MAX ? cmd.last + : CASENUMBER_MAX), cmd.step); + if (cmd.numbering == LST_NUMBERED) { struct fmt_spec fmt; diff --git a/tests/language/data-io/list.at b/tests/language/data-io/list.at index f8b3bb5c..4beeceed 100644 --- a/tests/language/data-io/list.at +++ b/tests/language/data-io/list.at @@ -84,6 +84,50 @@ Case Number,avar,bvar ]) AT_CLEANUP +# Checks for a crash when LIST did not include the variables from SPLIT +# FILE in the same positions (bug #30684). +AT_SETUP([LIST with split file]) +AT_DATA([data.txt], [dnl +a 1 +a 2 +a 3 +b 1 +c 4 +c 5 +]) +AT_DATA([list.sps], [dnl +DATA LIST LIST NOTABLE FILE='data.txt'/s (a1) n. +SPLIT FILE BY s. +LIST n. +]) +AT_CHECK([pspp -o pspp.csv list.sps]) +AT_CHECK([cat pspp.csv], [0], [dnl +Variable,Value,Label +s,a, + +Table: Data List +n +1.00 +2.00 +3.00 + +Variable,Value,Label +s,b, + +Table: Data List +n +1.00 + +Variable,Value,Label +s,c, + +Table: Data List +n +4.00 +5.00 +]) +AT_CLEANUP + AT_SETUP([LIST lots of variables]) AT_DATA([data.txt], [dnl 767532466348513789073483106409 -- 2.30.2