We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
CStringArray
Vec::push
1 parent 7e0430f commit bab4983Copy full SHA for bab4983
1 file changed
library/std/src/sys/process/unix/common/cstring_array.rs
@@ -35,10 +35,12 @@ impl CStringArray {
35
/// Push an additional string to the array.
36
pub fn push(&mut self, item: CString) {
37
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.
+ // Amend the array by another null pointer first, to ensure that the
+ // array is null-terminated even when the `push` panics, in which case
+ // the array will be left undisturbed (see #155748).
41
self.ptrs.push(ptr::null());
42
+ // Now, replace the previous null pointer.
43
+ self.ptrs[argc] = item.into_raw();
44
}
45
46
/// Returns a pointer to the C-string array managed by this type.
0 commit comments