From: Ben Pfaff Date: Mon, 17 Mar 2008 03:59:06 +0000 (+0000) Subject: Fix bug #22037. X-Git-Tag: v0.6.0~52 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4a500426ebcddef3d19dbbb0514f6dbb41f8d1e;p=pspp-builds.git Fix bug #22037. * 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. --- diff --git a/src/language/stats/ChangeLog b/src/language/stats/ChangeLog index 0f32d774..92a01000 100644 --- a/src/language/stats/ChangeLog +++ b/src/language/stats/ChangeLog @@ -1,3 +1,11 @@ +2008-03-16 Ben Pfaff + + 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 * regression.q (run_regression): Removed code for EXPORT diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index 3bffa2a3..fcfccc39 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -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); } } } diff --git a/tests/ChangeLog b/tests/ChangeLog index 7a601c4e..911cee50 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,11 @@ +2008-03-16 Ben Pfaff + + Bug #22037. + + * automake.mk: Add new test. + + * bugs/crosstabs-crash2.sh: New test. + 2008-03-16 Ben Pfaff Patch #6452. Reviewed by John Darrington. diff --git a/tests/automake.mk b/tests/automake.mk index abc327a5..a905a010 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -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 index 00000000..043aff87 --- /dev/null +++ b/tests/bugs/crosstabs-crash2.sh @@ -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 < /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;