aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-08-26 20:52:35 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2023-01-31 14:16:50 +0100
commit245ce6f26a1688ad69a1802ec50fa865db409eec (patch)
tree5f786306606c736a33ca3b9bd8a9f2bf9b68f9a6
parent3663d7ef66624b267114db5c59a959cdc7816aaa (diff)
downloadgcc-245ce6f26a1688ad69a1802ec50fa865db409eec.zip
gcc-245ce6f26a1688ad69a1802ec50fa865db409eec.tar.gz
gcc-245ce6f26a1688ad69a1802ec50fa865db409eec.tar.bz2
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<T>.pop_back()`. (TypeCheckContext::peek_context): Likewise for `std::vector<T>.back()`.
-rw-r--r--gcc/rust/typecheck/rust-tyctx.cc2
1 files changed, 2 insertions, 0 deletions
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;
}