Fixed a bug causing pspp to crash when computed variables had no format
authorJohn Darrington <john@darrington.wattle.id.au>
Fri, 20 Feb 2004 06:41:14 +0000 (06:41 +0000)
committerJohn Darrington <john@darrington.wattle.id.au>
Fri, 20 Feb 2004 06:41:14 +0000 (06:41 +0000)
defined, and were subsequently saved.

src/ChangeLog
src/compute.c
tests/Makefile.am
tests/bugs/compute-fmt.sh [new file with mode: 0755]

index f28af40317b6fcd69f558f2eeead79a5251b3c7e..2c524f329c25d3d360cd15a3fa8eb38f603c971a 100644 (file)
@@ -1,3 +1,10 @@
+Fri Feb 20 14:37:41 WAST 2004 John Darrington <john@darrington.wattle.id.au>
+
+       * compute.c: Fixed a bug where the Format was not getting set for 
+         computed variables (thus causing a crash when SAVEing).
+
+       * Added a test to stop this bug ever coming back
+
 Wed Feb 18 22:21:35 2004  Ben Pfaff  <blp@gnu.org>
 
        Got rid of approx.h.  In general, replaced all references to
index 0a1077d4666657c92a91116ab64557b5f0d7e11f..d26bf1ed2dd441d8f1406353b75b29b4105d227b 100644 (file)
@@ -397,11 +397,20 @@ lvalue_finalize (struct lvalue *lvalue,
     {
       compute->variable = dict_lookup_var (default_dict, lvalue->var_name);
       if (compute->variable == NULL)
-        compute->variable = dict_create_var_assert (default_dict,
-                                                    lvalue->var_name, 0);
+       {
+         struct fmt_spec input_spec = { 0,8,2 };
+         compute->variable = dict_create_var_assert (default_dict,
+                                                     lvalue->var_name, 0);
+
+                 convert_fmt_ItoO (&input_spec, &compute->variable->print);
+         compute->variable->write = compute->variable->print;
+       }
+
       compute->fv = compute->variable->fv;
       compute->width = compute->variable->width;
 
+      
+
       /* Goofy behavior, but compatible: Turn off LEAVE. */
       if (dict_class_from_id (compute->variable->name) != DC_SCRATCH)
         compute->variable->reinit = 1;
index b79cdbe025bfe5e336a3828ce400eb5d67fb5a51..c5c40adda14090fbcbd37ac2c1150aec8454fc94 100644 (file)
@@ -26,11 +26,12 @@ TESTS = command/aggregate.sh \
        command/t-test-groups.sh \
        command/weight.sh \
        bugs/alpha-freq.sh \
+       bugs/compute-fmt.sh \
        bugs/double-frequency.sh \
        bugs/html-frequency.sh \
        bugs/crosstabs.sh \
        bugs/data-crash.sh \
-       bugs/random.sh
+       bugs/random.sh 
 
 noinst_PROGRAMS = gengarbage
 
diff --git a/tests/bugs/compute-fmt.sh b/tests/bugs/compute-fmt.sh
new file mode 100755 (executable)
index 0000000..9094751
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+# This program tests for a bug which caused a crash after SAVE FILE
+# was called on a COMPUTEd variable
+
+
+TEMPDIR=/tmp/pspp-tst-$$
+
+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 > $TEMPDIR/foo.sps <<EOF
+INPUT PROGRAM.
+       COMPUTE num = 3.
+END FILE.
+END INPUT PROGRAM.
+EXECUTE.
+
+SAVE outfile='$TEMPDIR/temp.sav'.
+EOF
+if [ $? -ne 0 ] ; then no_result ; fi
+
+$SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/foo.sps
+if [ $? -ne 0 ] ; then fail; fi
+
+
+
+pass;