From 916d376c0868edf6d271a4fe9fdc96107f69002f Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sat, 4 Mar 2006 05:01:06 +0000 Subject: [PATCH] Fixed bug reading compressed system files. --- src/data/ChangeLog | 4 ++ src/data/sys-file-reader.c | 10 +++-- tests/automake.mk | 1 + tests/bugs/compression.sh | 90 ++++++++++++++++++++++++++++++++++++++ tests/test_template | 2 +- 5 files changed, 103 insertions(+), 4 deletions(-) create mode 100755 tests/bugs/compression.sh diff --git a/src/data/ChangeLog b/src/data/ChangeLog index c80710ca..e873a394 100644 --- a/src/data/ChangeLog +++ b/src/data/ChangeLog @@ -1,3 +1,7 @@ +Sat Mar 4 12:50:48 WST 2006 John Darrington + + * sys-file-reader.c: Fixed bug reading compressed files. + Thu Mar 2 08:40:33 WST 2006 John Darrington * Numerous renames. See src/ChangeLog for details. diff --git a/src/data/sys-file-reader.c b/src/data/sys-file-reader.c index c8c70342..9a3faf6a 100644 --- a/src/data/sys-file-reader.c +++ b/src/data/sys-file-reader.c @@ -1399,9 +1399,13 @@ read_compressed_data (struct sfm_reader *r, flt64 *buf) if (r->ptr == NULL || r->ptr >= r->end) { if (!buffer_input (r)) - if (buf_beg != buf) - lose ((ME, _("%s: Unexpected end of file."), - fh_get_filename (r->fh))); + { + if (buf_beg != buf) + lose ((ME, _("%s: Unexpected end of file."), + fh_get_filename (r->fh))); + else + return 0; + } } memcpy (r->x, r->ptr++, sizeof *buf); p = r->x; diff --git a/tests/automake.mk b/tests/automake.mk index 64a2b712..cfe41fa1 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -59,6 +59,7 @@ TESTS = \ tests/bugs/big-input-2.sh \ tests/bugs/comment-at-eof.sh \ tests/bugs/compute-fmt.sh \ + tests/bugs/compression.sh \ tests/bugs/crosstabs.sh \ tests/bugs/crosstabs-crash.sh \ tests/bugs/curtailed.sh \ diff --git a/tests/bugs/compression.sh b/tests/bugs/compression.sh new file mode 100755 index 00000000..e705480c --- /dev/null +++ b/tests/bugs/compression.sh @@ -0,0 +1,90 @@ +#!/bin/sh + +# This program tests that compressed system files can be read and written + +TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps + +# ensure that top_srcdir and top_builddir are absolute +if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi +if [ -z "$top_builddir" ] ; then top_builddir=. ; fi +top_srcdir=`cd $top_srcdir; pwd` +top_builddir=`cd $top_builddir; pwd` + +export STAT_CONFIG_PATH=$top_srcdir/config + + +cleanup() +{ + if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then + echo "NOT cleaning $TEMPDIR" + return ; + fi + 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 + +cat > $TESTFILE < /dev/null | od > $TEMPDIR/file +if [ $? -ne 0 ] ; then no_result ; fi + +activity="check compression byte" +diff $TEMPDIR/file - <