segment: Fix segmentation of integer followed by "." at end of file.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 9 Apr 2021 17:32:18 +0000 (10:32 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 9 Apr 2021 18:16:48 +0000 (11:16 -0700)
Previously this was segmented as a single number containing a trailing dot,
but it should be an integer followed by end-of-command.

src/language/lexer/segment.c
tests/language/lexer/lexer.at
tests/language/lexer/segment.at

index 93eb1e8f8594b564d768737f5e84057da8085009..3e060a5b9f9e9e3d8342ad641d47dad594b953df 100644 (file)
@@ -286,20 +286,23 @@ segmenter_parse_number__ (struct segmenter *s, const char *input, size_t n,
       if (!eof)
         return -1;
       goto number;
-    };
+    }
   if (input[ofs] == '.')
     {
+      if (ofs + 1 >= n)
+        {
+          if (!eof)
+            return -1;
+          goto number;
+        }
+
       ofs = skip_digits (input, n, eof, ofs + 1);
       if (ofs < 0)
         return -1;
+      else if (ofs >= n)
+        goto number;
     }
 
-  if (ofs >= n)
-    {
-      if (!eof)
-        return -1;
-      goto number;
-    }
   if (input[ofs] == 'e' || input[ofs] == 'E')
     {
       ofs++;
index e664ac2ad7c209925558c732176d1873eb2ef446..d499f0922f7cd2e20cd35fc2fb9b579d7d2d98c5 100644 (file)
@@ -103,7 +103,7 @@ AT_SETUP([lexer crash due to overflow])
 printf "DATA LIST/5555555555555555." > lexer.sps
 
 AT_CHECK([pspp -O format=csv lexer.sps], [1], [dnl
-lexer.sps:1.11-1.27: error: DATA LIST: Syntax error at `5555555555555555.': Expected integer between 1 and 2147483647.
+lexer.sps:1.11-1.26: error: DATA LIST: Syntax error at `5555555555555555': Expected integer between 1 and 2147483647.
 ])
 
 AT_CLEANUP
index 04a77a9b8fd103ebc0b09e3a2533cc7e13d7d32d..b358b3e509affef6590c1894239592309bef5454 100644 (file)
@@ -345,7 +345,7 @@ AT_DATA([input], [dnl
 5e1 6E-1 7e+1 6E+01 6e-03
 .3E1 .4e-1 .5E+1 .6e+01 .7E-03
 1.23e1 45.6E-1 78.9e+1 99.9E+01 11.2e-03
-. 1e e1 1e+ 1e-
+. 1e e1 1e+ 1e- 1.
 ])
 AT_DATA([expout-base], [dnl
 number          0    space
@@ -395,8 +395,10 @@ start_command   .    space
 expected_exponent 1e    space
 identifier      e1    space
 expected_exponent 1e+    space
-expected_exponent 1e-
--newline         \n (later)
+expected_exponent 1e-    space
+number          1
+end_command     .
+-newline         \n (first)
 -
 end
 ])