From d01a223942ec2ae4745788b9c006f83fe22050ba Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 3 Apr 2004 19:45:09 +0000 Subject: [PATCH] Fix infinite loop on comment at end of file, add test. --- src/ChangeLog | 5 ++++ src/lexer.c | 10 +++++-- tests/ChangeLog | 8 +++++ tests/Makefile.am | 30 ++++++++++--------- tests/bugs/comment-at-eof.sh | 58 ++++++++++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 16 deletions(-) create mode 100755 tests/bugs/comment-at-eof.sh diff --git a/src/ChangeLog b/src/ChangeLog index 4d9e68b2..aa27da7d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +Sat Apr 3 11:43:37 2004 Ben Pfaff + + * lexer.c: (lex_skip_comment) Handle end-of-file correctly (I + hope). + Sat Apr 3 15:00:18 WST 2004 John Darrington * frequencies.q: Fixed the calculation of percentiles diff --git a/src/lexer.c b/src/lexer.c index dd20c8b9..df48d4ec 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -71,7 +71,7 @@ static char *prog; /* Nonzero only if this line ends with a terminal dot. */ static int dot; -/* Nonzero only if the last token returned was T_EOF. */ +/* Nonzero only if the last token returned was T_STOP. */ static int eof; /* If nonzero, next token returned by lex_get(). @@ -968,7 +968,13 @@ lex_skip_comment (void) { for (;;) { - lex_get_line (); + if (!lex_get_line ()) + { + put_token = T_STOP; + eof = 1; + return; + } + if (put_token == '.') break; diff --git a/tests/ChangeLog b/tests/ChangeLog index 7bfa7f34..1e52c8f8 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,11 @@ +Sat Apr 3 11:42:31 2004 Ben Pfaff + + * Makefile.am: (TESTS) Add bugs/comment-at-eof.sh. Alphabetize + test order. + + * bugs/comment-at-eof.sh: Add test for a bug where a comment at + end of file caused an infinite loop. + Sat Mar 27 11:29:06 WST 2004 John Darrington * bugs/get.sh Added regression test for a bug in loading a dictionary diff --git a/tests/Makefile.am b/tests/Makefile.am index 1d8f3c02..6434ab02 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,7 +1,8 @@ ## Process this file with automake to produce Makefile.in -*- makefile -*- TESTS_ENVIRONMENT=top_srcdir=${top_srcdir} -TESTS = command/aggregate.sh \ +TESTS = \ + command/aggregate.sh \ command/autorecod.sh \ command/beg-data.sh \ command/bignum.sh \ @@ -16,31 +17,32 @@ TESTS = command/aggregate.sh \ command/print.sh \ command/sample.sh \ command/sort.sh \ - command/tabs.sh \ command/split-file.sh \ - command/t-test-1s.sh \ - command/t-test-pairs.sh \ - command/t-test-groups.sh \ command/t-test-1-indep-val.sh \ - command/t-test-1-sample-missing-list.sh \ - command/t-test-paired-missing-list.sh \ - command/t-test-paired-missing-anal.sh \ command/t-test-1-sample-missing-anal.sh \ - command/t-test-indep-missing-list.sh \ + command/t-test-1-sample-missing-list.sh \ + command/t-test-1s.sh \ + command/t-test-groups.sh \ command/t-test-indep-missing-anal.sh \ + command/t-test-indep-missing-list.sh \ + command/t-test-paired-missing-anal.sh \ + command/t-test-paired-missing-list.sh \ + command/t-test-pairs.sh \ + command/tabs.sh \ command/use.sh \ command/weight.sh \ bugs/alpha-freq.sh \ + bugs/comment-at-eof.sh \ bugs/compute-fmt.sh \ + bugs/crosstabs.sh \ + bugs/data-crash.sh \ bugs/double-frequency.sh \ bugs/get.sh \ bugs/html-frequency.sh \ - bugs/crosstabs.sh \ - bugs/data-crash.sh \ bugs/multipass.sh \ bugs/random.sh \ - bugs/t-test.sh \ bugs/t-test-with-temp.sh \ + bugs/t-test.sh \ bugs/temporary.sh \ bugs/val-labs.sh \ xforms/casefile.sh \ @@ -48,8 +50,8 @@ TESTS = command/aggregate.sh \ stats/descript-basic.sh \ stats/descript-missing.sh \ stats/moments.sh \ - stats/percentiles-enhanced.sh \ - stats/percentiles-compatible.sh + stats/percentiles-compatible.sh \ + stats/percentiles-enhanced.sh noinst_PROGRAMS = gengarbage diff --git a/tests/bugs/comment-at-eof.sh b/tests/bugs/comment-at-eof.sh new file mode 100755 index 00000000..0042b431 --- /dev/null +++ b/tests/bugs/comment-at-eof.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# Tests for a bug wherein a comment just before end-of-file caused an +# infinite loop. Thus, this test passes as long as it completes. + +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 <