From c99827349927a44334f2b04139168efd0bc87cd3 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 1 Jul 2022 20:16:06 +0200 Subject: [PATCH] [pseudo] Fix an out-of-bound issue in getReduceRules. --- .../pseudo/include/clang-pseudo/grammar/LRTable.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h b/clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h index 70ce52924f11..664a1a3206fe 100644 --- a/clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h +++ b/clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h @@ -140,8 +140,11 @@ public: // // ...apply reduce... // } llvm::ArrayRef getReduceRules(StateID State) const { + if (ReduceOffset[State] >= Reduces.size()) + return {}; + size_t Length = ReduceOffset[State + 1] - ReduceOffset[State]; return llvm::makeArrayRef(&Reduces[ReduceOffset[State]], - &Reduces[ReduceOffset[State + 1]]); + Length); } // Returns whether Terminal can follow Nonterminal in a valid source file. bool canFollow(SymbolID Nonterminal, SymbolID Terminal) const {