Fix infinite loop on comment at end of file, add test.
authorBen Pfaff <blp@gnu.org>
Sat, 3 Apr 2004 19:45:09 +0000 (19:45 +0000)
committerBen Pfaff <blp@gnu.org>
Sat, 3 Apr 2004 19:45:09 +0000 (19:45 +0000)
src/ChangeLog
src/lexer.c
tests/ChangeLog
tests/Makefile.am
tests/bugs/comment-at-eof.sh [new file with mode: 0755]

index 4d9e68b205bc5946bf4c2c98c442fc99d3cb2595..aa27da7d6bd50f25aed8edfacd4e1a4f4b3966c1 100644 (file)
@@ -1,3 +1,8 @@
+Sat Apr  3 11:43:37 2004  Ben Pfaff  <blp@gnu.org>
+
+       * lexer.c: (lex_skip_comment) Handle end-of-file correctly (I
+       hope).
+
 Sat Apr  3 15:00:18 WST 2004 John Darrington <john@darrington.wattle.id.au>
 
         * frequencies.q:  Fixed the calculation of percentiles
index dd20c8b9524db89a474dc1bad03c2e0eac34223a..df48d4eca5499c5fbaf82cfd8b2ba6ea70a4c586 100644 (file)
@@ -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;
 
index 7bfa7f34b8eca20ddd6f20cb8355d7f14e279865..1e52c8f85c6fbcdb33928ad75552c41ee20fc304 100644 (file)
@@ -1,3 +1,11 @@
+Sat Apr  3 11:42:31 2004  Ben Pfaff  <blp@gnu.org>
+
+       * 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 <john@darrington.wattle.id.au>
 
        * bugs/get.sh Added regression test for a bug in loading a dictionary
index 1d8f3c0286feeccc9bfe3fe8468cdb06063d2819..6434ab0258388ae4748233842662b6a051b02fdd 100644 (file)
@@ -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 (executable)
index 0000000..0042b43
--- /dev/null
@@ -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 <<EOF
+COMMENT this is a comment at end of file.
+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;