https://gcc.gnu.org/g:5f0e77ad4623bc5450808367d902836b7257066b

commit 5f0e77ad4623bc5450808367d902836b7257066b
Author: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>
Date:   Fri Nov 17 15:26:43 2023 +0100

    fixup: Ensure buffer allocation for bootstrap
    
    Bootstrap was failing because the vector did not allocate the internal
    buffer and was holding a null pointer.
    
    Commit to fixup is b71fd2afa831
    
    gcc/rust/ChangeLog:
    
            * expand/rust-proc-macro.cc (generate_proc_macro_decls_symbol): 
Resize
            the vector and initialize it with dummy data before changing it.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>

Diff:
---
 gcc/rust/expand/rust-proc-macro.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/expand/rust-proc-macro.cc 
b/gcc/rust/expand/rust-proc-macro.cc
index 3865b87b75b2..c5bd87a05a51 100644
--- a/gcc/rust/expand/rust-proc-macro.cc
+++ b/gcc/rust/expand/rust-proc-macro.cc
@@ -183,7 +183,8 @@ generate_proc_macro_decls_symbol (std::uint32_t 
stable_crate_id)
   // Size could be hardcoded since we know the input size but I elected to
   // calculate it everytime so we won't have any desync between code and data.
   int size = std::snprintf (nullptr, 0, PROC_MACRO_DECLS_FMT_ARGS);
-  std::vector<char> buf (size + 1);
+  std::vector<char> buf;
+  buf.resize (size + 1, '\0');
   std::sprintf (buf.data (), PROC_MACRO_DECLS_FMT_ARGS);
 #undef PROC_MACRO_DECLS_FMT_ARGS

Reply via email to