]> git.mdlowis.com Git - archive/parse-utils.git/commitdiff
Fixed off-by-one error in btparser and llnlexer.
authorMike D. Lowis <mike@mdlowis.com>
Fri, 6 Apr 2012 16:36:45 +0000 (12:36 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Fri, 6 Apr 2012 16:36:45 +0000 (12:36 -0400)
source/lexer/llnlexer/llnlexer.cpp
source/parser/btparser/btparser.cpp

index 553f303da389ff1a6db44051c5e2add59fbee7b2..9b265630f4008da9a6731dc2eeb44c0768b9236b 100644 (file)
@@ -12,7 +12,7 @@ LLNLexer::~LLNLexer()
 void LLNLexer::consume(void)
 {
     cur_idx++;
-    if(cur_idx == la_buffer.size())
+    if(cur_idx >= la_buffer.size())
     {
         cur_idx = 0;
         la_buffer.clear();
@@ -37,8 +37,13 @@ void LLNLexer::match(char match)
 void LLNLexer::sync(unsigned int i)
 {
     unsigned int next_index = cur_idx + i - 1;
-    unsigned int max_index = (la_buffer.size() == 0) ? 0 : (la_buffer.size() - 1);
-    if( next_index >= max_index )
+    unsigned int max_index = (la_buffer.size() - 1);
+
+    if( la_buffer.size() == 0 )
+    {
+        fill(i);
+    }
+    else if( next_index >= max_index )
     {
         fill( next_index - max_index);
     }
@@ -47,7 +52,7 @@ void LLNLexer::sync(unsigned int i)
 void LLNLexer::fill(unsigned int n)
 {
     unsigned int i = 0;
-    for (i = 0; i <= n; i++)
+    for (i = 0; i < n; i++)
     {
         la_buffer.push_back( in_stream.get() );
     }
index 3bf3e3c56ad52f25432d9dda74a76c5396ee2bdf..4e3a8d5c2db3e5345764e4676466fe06c4d3b551 100644 (file)
@@ -25,8 +25,13 @@ void BTParser::consume(void)
 void BTParser::sync(unsigned int i)
 {
     unsigned int next_index = current + i - 1;
-    unsigned int max_index = (lookahead.size() == 0) ? 0 : (lookahead.size() - 1);
-    if( next_index >= max_index )
+    unsigned int max_index = (lookahead.size() - 1);
+
+    if( lookahead.size() == 0 )
+    {
+        fill(i);
+    }
+    else if( next_index >= max_index )
     {
         fill( next_index - max_index);
     }
@@ -35,7 +40,7 @@ void BTParser::sync(unsigned int i)
 void BTParser::fill(unsigned int n)
 {
     unsigned int i = 0;
-    for (i = 0; i <= n; i++)
+    for (i = 0; i < n; i++)
     {
         lookahead.push_back( lexer->next() );
     }