File tree Expand file tree Collapse file tree
library/std/src/sys/process/unix/common
src/doc/rustc/src/platform-support Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,10 +35,12 @@ impl CStringArray {
3535 /// Push an additional string to the array.
3636 pub fn push ( & mut self , item : CString ) {
3737 let argc = self . ptrs . len ( ) - 1 ;
38- // Replace the null pointer at the end of the array...
39- self . ptrs [ argc ] = item . into_raw ( ) ;
40- // ... and recreate it to restore the data structure invariant .
38+ // Amend the array by another null pointer first, to ensure that the
39+ // array is null-terminated even when the `push` panics, in which case
40+ // the array will be left undisturbed (see #155748) .
4141 self . ptrs . push ( ptr:: null ( ) ) ;
42+ // Now, replace the previous null pointer.
43+ self . ptrs [ argc] = item. into_raw ( ) ;
4244 }
4345
4446 /// Returns a pointer to the C-string array managed by this type.
Original file line number Diff line number Diff line change 22
33** Tier: 2 (with host tools)**
44
5- Windows targets similar to ` *-windows-gnu ` but using UCRT as the runtime and various LLVM tools/libraries instead of
5+ Windows targets similar to ` *-windows-gnu ` but using Universal C Runtime ( UCRT) as the runtime and various LLVM tools/libraries instead of
66GCC/Binutils.
77
88Target triples available so far:
You can’t perform that action at this time.
0 commit comments