From 5f0e77ad4623bc5450808367d902836b7257066b Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Fri, 17 Nov 2023 15:26:43 +0100 Subject: [PATCH] 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 --- 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 buf (size + 1); + std::vector buf; + buf.resize (size + 1, '\0'); std::sprintf (buf.data (), PROC_MACRO_DECLS_FMT_ARGS); #undef PROC_MACRO_DECLS_FMT_ARGS