From 12f1ba95a6eb660bf60b8e6a1bb09ecffee16630 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 29 Apr 2005 01:29:31 +0000 Subject: [PATCH] Fixed bug in single arity version of LAG. --- src/ChangeLog | 5 +++ src/expressions/parse.c | 4 ++- src/vfm.c | 4 ++- tests/Makefile.am | 1 + tests/bugs/lag_crash.sh | 71 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 2 deletions(-) create mode 100755 tests/bugs/lag_crash.sh diff --git a/src/ChangeLog b/src/ChangeLog index 1a9d2659..9259c9f9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +Fri Apr 29 09:28:00 WST 2005 John Darrington + + * expressions/parse.c: Added handler for OP_LAG_Vn and OP_LAG_Vs. + Fixed bug [#12858] . + Wed Apr 27 12:42:34 WST 2005 John Darrington * loop.c recode.c repeat.c: Fixed a couple of instances of SHORT_NAME_LEN diff --git a/src/expressions/parse.c b/src/expressions/parse.c index ba790d08..0abfbb8a 100644 --- a/src/expressions/parse.c +++ b/src/expressions/parse.c @@ -1204,7 +1204,9 @@ parse_function (struct expression *e) n = expr_allocate_composite (e, f - operations, args, arg_cnt); n->composite.min_valid = min_valid != -1 ? min_valid : f->array_min_elems; - if (n->type == OP_LAG_Vnn || n->type == OP_LAG_Vsn) + if (n->type == OP_LAG_Vn || n->type == OP_LAG_Vs) + n_lag = 1; + else if (n->type == OP_LAG_Vnn || n->type == OP_LAG_Vsn) { int n_before; assert (n->composite.arg_cnt == 2); diff --git a/src/vfm.c b/src/vfm.c index 5afa838d..6944df2b 100644 --- a/src/vfm.c +++ b/src/vfm.c @@ -584,7 +584,9 @@ const struct case_sink_class null_sink_class = struct ccase * lagged_case (int n_before) { - assert (n_before >= 1 && n_before <= n_lag); + assert (n_before >= 1 ); + assert (n_before <= n_lag); + if (n_before <= lag_count) { int index = lag_head - n_before; diff --git a/tests/Makefile.am b/tests/Makefile.am index b14643e4..f2cabf49 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -64,6 +64,7 @@ TESTS = \ bugs/get-no-file.sh \ bugs/html-frequency.sh \ bugs/if_crash.sh \ + bugs/lag_crash.sh \ bugs/multipass.sh \ bugs/random.sh \ bugs/t-test-with-temp.sh \ diff --git a/tests/bugs/lag_crash.sh b/tests/bugs/lag_crash.sh new file mode 100755 index 00000000..72683b28 --- /dev/null +++ b/tests/bugs/lag_crash.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# This program tests for a bug which crashed pspp when using LAG + +TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps + +here=`pwd`; + +# ensure that top_srcdir is absolute +cd $top_srcdir; top_srcdir=`pwd` + +export STAT_CONFIG_PATH=$top_srcdir/config + + +cleanup() +{ + rm -rf $TEMPDIR +} + + +fail() +{ + echo $activity + echo FAILED + cleanup; + exit 1; +} + + +no_result() +{ + echo $activity + echo NO RESULT; + cleanup; + exit 2; +} + +pass() +{ + cleanup; + exit 0; +} + +mkdir -p $TEMPDIR + +cd $TEMPDIR + +activity="create program" +cat > $TESTFILE << EOF +DATA LIST LIST /x. +BEGIN DATA +1 +2 +END DATA. + +DO IF (x <> LAG(x) ). + ECHO 'hello'. +END IF. + +EXECUTE. +EOF +if [ $? -ne 0 ] ; then no_result ; fi + + +activity="run_program" +$SUPERVISOR $here/../src/pspp $TESTFILE > /dev/null +if [ $? -ne 0 ] ; then fail ; fi + + +pass; -- 2.30.2