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]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/00b34042269a7ea959d07691971d216aca375b7d

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4730

 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 e7a31b9df..d11ded9c9 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]; }

base-commit: 88c04c2dacbdbb6ef72ef627ed05cc2f7f725c54
-- 
2.54.0

Reply via email to