Fix bug #22037.
authorBen Pfaff <blp@gnu.org>
Mon, 17 Mar 2008 03:59:06 +0000 (03:59 +0000)
committerBen Pfaff <blp@gnu.org>
Mon, 17 Mar 2008 03:59:06 +0000 (03:59 +0000)
* crosstabs.q (calc_general): Only the short string prefix of long
string variables are tabulated, so we must not copy or zero out
more data than that.

src/language/stats/ChangeLog
src/language/stats/crosstabs.q
tests/ChangeLog
tests/automake.mk
tests/bugs/crosstabs-crash2.sh [new file with mode: 0755]

index 0f32d77472d87ff0e2a5c995ef67fccc2f7b3a78..92a01000496f5c00b1eda3ef6feafc7716876cbd 100644 (file)
@@ -1,3 +1,11 @@
+2008-03-16  Ben Pfaff  <blp@gnu.org>
+
+       Bug #22037.  Thanks to John Darrington for reporting this bug.
+       
+       * crosstabs.q (calc_general): Only the short string prefix of long
+       string variables are tabulated, so we must not copy or zero out
+       more data than that.
+
 2008-03-10  Jason Stover  <jhs@debs.hoobahooba.net>
 
        * regression.q (run_regression): Removed code for EXPORT
index 3bffa2a32f5839f712548f8f07e4f765fe719c6c..fcfccc39a251c2fbbfffbda7a6913207a70d1757 100644 (file)
@@ -637,12 +637,14 @@ calc_general (struct ccase *c, const struct dataset *ds)
              te->values[j].f = case_num (c, x->vars[j]);
            else
              {
-               memcpy (te->values[j].s, case_str (c, x->vars[j]),
-                        var_get_width (x->vars[j]));
+                size_t n = var_get_width (x->vars[j]);
+                if (n > MAX_SHORT_STRING)
+                  n = MAX_SHORT_STRING;
+               memcpy (te->values[j].s, case_str (c, x->vars[j]), n);
 
                /* Necessary in order to simplify comparisons. */
                memset (&te->values[j].s[var_get_width (x->vars[j])], 0,
-                       sizeof (union value) - var_get_width (x->vars[j]));
+                       sizeof (union value) - n);
              }
          }
       }
index 7a601c4e9483e9f0b9c533b70a9cec80e7d003ec..911cee50cd1399e5e0ea5ade52dc14083fd2a33b 100644 (file)
@@ -1,3 +1,11 @@
+2008-03-16  Ben Pfaff  <blp@gnu.org>
+
+       Bug #22037.
+
+       * automake.mk: Add new test.
+
+       * bugs/crosstabs-crash2.sh: New test.
+
 2008-03-16  Ben Pfaff  <blp@gnu.org>
 
        Patch #6452.  Reviewed by John Darrington.
index abc327a5ab67b84a99d08d0bf34af6a769bb8048..a905a010b9bac29b43021b1aa3519e6db49e0e7f 100644 (file)
@@ -100,6 +100,7 @@ dist_TESTS = \
        tests/bugs/compression.sh \
        tests/bugs/crosstabs.sh \
        tests/bugs/crosstabs-crash.sh \
+       tests/bugs/crosstabs-crash2.sh \
        tests/bugs/curtailed.sh \
        tests/bugs/data-crash.sh \
        tests/bugs/double-frequency.sh \
diff --git a/tests/bugs/crosstabs-crash2.sh b/tests/bugs/crosstabs-crash2.sh
new file mode 100755 (executable)
index 0000000..043aff8
--- /dev/null
@@ -0,0 +1,112 @@
+#!/bin/sh
+
+# This program tests for bug #22037, which caused CROSSTABS to crash.
+
+TEMPDIR=/tmp/pspp-tst-$$
+TESTFILE=$TEMPDIR/`basename $0`.sps
+
+# ensure that top_builddir  are absolute
+if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
+if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
+top_builddir=`cd $top_builddir; pwd`
+PSPP=$top_builddir/src/ui/terminal/pspp
+
+# ensure that top_srcdir is absolute
+top_srcdir=`cd $top_srcdir; pwd`
+
+STAT_CONFIG_PATH=$top_srcdir/config
+export STAT_CONFIG_PATH
+
+LANG=C
+export LANG
+
+cleanup()
+{
+     cd /
+     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 * y (a18).
+
+begin data.
+
+   1. 'zero none'
+
+1 'one unity'
+2 'two duality'
+3 'three lots'
+end data.
+
+CROSSTABS /TABLES = x BY y.
+EOF
+if [ $? -ne 0 ] ; then no_result ; fi
+
+$SUPERVISOR $PSPP --testing-mode $TESTFILE > /dev/null
+if [ $? -ne 0 ] ; then no_result ; fi
+
+perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
+diff -b  -w $TEMPDIR/pspp.list - << EOF
+1.1 DATA LIST.  Reading free-form data from INLINE.
++--------+------+
+|Variable|Format|
+#========#======#
+|x       |F8.0  |
+|y       |A18   |
++--------+------+
+$TEMPDIR/crosstabs-crash2.sh.sps:4: warning: BEGIN DATA: Missing value(s) for all variables from x onward.  These will be filled with the system-missing value or blanks, as appropriate.
+$TEMPDIR/crosstabs-crash2.sh.sps:6: warning: BEGIN DATA: Missing value(s) for all variables from x onward.  These will be filled with the system-missing value or blanks, as appropriate.
+2.1 CROSSTABS.  Summary.
+#===============#=====================================================#
+#               #                        Cases                        #
+#               #-----------------+-----------------+-----------------#
+#               #      Valid      |     Missing     |      Total      #
+#               #--------+--------+--------+--------+--------+--------#
+#               #       N| Percent|       N| Percent|       N| Percent#
+#---------------#--------+--------+--------+--------+--------+--------#
+#x * y          #       4|   66.7%|       2|   33.3%|       6|  100.0%#
+#===============#========#========#========#========#========#========#
+2.2 CROSSTABS.  x by y [count].
+#===============#===================================#========#
+#               #                 y                 |        #
+#               #--------+--------+--------+--------+        #
+#              x#one unit|three lo|two dual|zero non|  Total #
+#---------------#--------+--------+--------+--------+--------#
+#           1.00#     1.0|      .0|      .0|     1.0|     2.0#
+#           2.00#      .0|      .0|     1.0|      .0|     1.0#
+#           3.00#      .0|     1.0|      .0|      .0|     1.0#
+#Total          #    1.0%|    1.0%|    1.0%|    1.0%|    4.0%#
+#===============#========#========#========#========#========#
+EOF
+if [ $? -ne 0 ] ; then fail ; fi
+
+pass;