From: Lishin <[email protected]>

Create the requested number of elements in the IndexVec constructor
instead of only reserving space. This fixes an out-of-bounds access
when dumping BIR.

gcc/rust/ChangeLog:

        * checks/errors/borrowck/rust-bir-place.h
        (IndexVec::IndexVec): Create the requested number of elements.

Signed-off-by: Lishin <[email protected]>
---
 gcc/rust/checks/errors/borrowck/rust-bir-place.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
index e7a31b9df6d..d11ded9c9da 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
@@ -209,7 +209,7 @@ template <typename I, typename T> class IndexVec
 
 public:
   IndexVec () = default;
-  IndexVec (size_t size) { internal_vector.reserve (size); }
+  IndexVec (size_t size) : internal_vector (size) {}
 
   T &at (I pid) { return internal_vector[pid.value]; }
   const T &at (I pid) const { return internal_vector[pid.value]; }
-- 
2.50.1

Reply via email to