X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/10454ea42fefb0a4efe337c1ef54cd99a4e2001a..fd19f2714f56e972cc03dba474399a89af630699:/data/lalr1.cc diff --git a/data/lalr1.cc b/data/lalr1.cc index b921b818..8e82cb51 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -810,24 +810,30 @@ yy::]b4_parser_class_name[::yyreport_syntax_error_ () yyn_ = yypact_[yystate_]; if (yypact_ninf_ < yyn_ && yyn_ < yylast_) { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + int yyxbegin = yyn_ < 0 ? -yyn_ : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = yylast_ - yyn_; + int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; + int count = 0; + for (int x = yyxbegin; x < yyxend; ++x) + if (yycheck_[x + yyn_] == x && x != yyterror_) + ++count; + message = "syntax error, unexpected "; message += yyname_[yyilooka_]; - { - int count = 0; - for (int x = (yyn_ < 0 ? -yyn_ : 0); x < yyntokens_ + yynnts_; ++x) - if (yycheck_[x + yyn_] == x && x != yyterror_) - ++count; - if (count < 5) - { - count = 0; - for (int x = (yyn_ < 0 ? -yyn_ : 0); x < yyntokens_ + yynnts_; ++x) - if (yycheck_[x + yyn_] == x && x != yyterror_) - { - message += (!count++) ? ", expecting " : " or "; - message += yyname_[x]; - } - } - } + if (count < 5) + { + count = 0; + for (int x = yyxbegin; x < yyxend; ++x) + if (yycheck_[x + yyn_] == x && x != yyterror_) + { + message += (!count++) ? ", expecting " : " or "; + message += yyname_[x]; + } + } } else #endif