We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
write_with
1 parent 9a6e8b3 commit c8e7c62Copy full SHA for c8e7c62
compiler/rustc_serialize/src/opaque/mem_encoder.rs
@@ -35,8 +35,15 @@ impl MemEncoder {
35
self.data.reserve(N);
36
37
let old_len = self.data.len();
38
- // SAFETY: fix
39
- let buf = unsafe { &mut *(self.data.as_mut_ptr().add(old_len) as *mut [u8; N]) };
+
+ // SAFETY: The above `reserve` ensures that there is enough
40
+ // room to write the encoded value to the vector's internal buffer.
41
+ // The memory is also initialized as 0.
42
+ let buf = unsafe {
43
+ let buf = self.data.as_mut_ptr().add(old_len) as *mut [u8; N];
44
+ *buf = [0; N];
45
+ &mut *buf
46
+ };
47
let written = visitor(buf);
48
if written > N {
49
Self::panic_invalid_write::<N>(written);
0 commit comments