[COMMITTED 18/43] gccrs: Fix sized BIR IndexVec construction

arthur.cohen@opensrcsec.com arthur.cohen@opensrcsec.com
Thu Sep 10 08:19:31 GMT 2026


From: Lishin <lishin1008@gmail.com>

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 <lishin1008@gmail.com>
---
 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



More information about the Gcc-rust mailing list