From 245ce6f26a1688ad69a1802ec50fa865db409eec Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Fri, 26 Aug 2022 20:52:35 +0100 Subject: [PATCH] gccrs: Add guards against getting data from an empty vector gcc/rust/ChangeLog: * typecheck/rust-tyctx.cc (TypeCheckContext::pop_return_type): Add guards around `std::vector.pop_back()`. (TypeCheckContext::peek_context): Likewise for `std::vector.back()`. --- gcc/rust/typecheck/rust-tyctx.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gcc/rust/typecheck/rust-tyctx.cc b/gcc/rust/typecheck/rust-tyctx.cc index ad5f67c..af86b06 100644 --- a/gcc/rust/typecheck/rust-tyctx.cc +++ b/gcc/rust/typecheck/rust-tyctx.cc @@ -142,12 +142,14 @@ TypeCheckContext::push_return_type (TypeCheckContextItem item, void TypeCheckContext::pop_return_type () { + rust_assert (!return_type_stack.empty ()); return_type_stack.pop_back (); } TypeCheckContextItem & TypeCheckContext::peek_context () { + rust_assert (!return_type_stack.empty ()); return return_type_stack.back ().first; } -- 2.7.4