]> git.saurik.com Git - bison.git/blobdiff - data/lalr1.cc
* data/yacc.c, data/glr.c, data/lal1.cc: Use similar code to
[bison.git] / data / lalr1.cc
index 1d1b9cff16912aeb3756da36ab17050f0ec8cd06..34398cc1211dd8e569c555d91f8da8386c81df2d 100644 (file)
@@ -498,13 +498,19 @@ b4_syncline([@oline@], [@ofile@])[
          message += name_[ilooka_];
          {
            int count = 0;
-           for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x)
+            /* Start YYX at -YYN if negative to avoid negative indexes in
+               YYCHECK.  */
+           int xbegin = n_ < 0 ? -n_ : 0;
+           /* Stay within bounds of both yycheck and yytname.  */
+           int checklim = last_ - n_;
+           int xend = checklim < ntokens_ ? checklim : ntokens_;
+           for (int x = xbegin; x < xend; ++x)
              if (check_[x + n_] == x && x != terror_)
                ++count;
            if (count < 5)
              {
                count = 0;
-               for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x)
+               for (int x = xbegin; x < xend; ++x)
                  if (check_[x + n_] == x && x != terror_)
                    {
                      message += (!count++) ? ", expecting " : " or ";