X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/d5286af19bd4743eaef1d7ee81c1f091f7449711..c47495657bb2f35012e35668a2c6c149e1bed3ac:/data/lalr1.cc diff --git a/data/lalr1.cc b/data/lalr1.cc index 1d1b9cff..34398cc1 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -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 ";