]> git.saurik.com Git - bison.git/blobdiff - data/lalr1.cc
Sync with latest FSF version.
[bison.git] / data / lalr1.cc
index e1ad791ae7e5cc01261f7f0ae9419c1bd4e05d21..34398cc1211dd8e569c555d91f8da8386c81df2d 100644 (file)
@@ -432,8 +432,9 @@ yy::]b4_parser_class_name[::parse ()
       // Short files will use "unsigned char" for line numbers,
       // in which case they will be output as character litterals
       // by "<<".
+      unsigned yylno = rline_[n_];
       YYCDEBUG << "Reducing via rule " << n_ - 1
-               << " (line " << static_cast <unsigned> (rline_[n_]) << "), ";
+               << " (line " << yylno << "), ";
       for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_];
           0 <= rhs_[i]; ++i)
        YYCDEBUG << name_[rhs_[i]] << ' ';
@@ -497,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 ";
@@ -923,7 +930,9 @@ namespace yy
     /** \brief (column related) Advance to the COLUMNS next columns. */
     inline void columns (int columns = 1)
     {
-      if (int (initial_column) < columns + int (column))
+      int leftmost = initial_column;
+      int current  = column;
+      if (leftmost <= current + columns)
        column += columns;
       else
        column = initial_column;