Skip to content

Commit 75ed447

Browse files
authored
Merge pull request #1213 from djmitche/safety-comment
Add a safety comment to unsafe block
2 parents be2198a + 73011c0 commit 75ed447

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/read.rs

+4
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,10 @@ fn push_wtf8_codepoint(n: u32, scratch: &mut Vec<u8>) {
977977

978978
scratch.reserve(4);
979979

980+
// SAFETY: After the `reserve` call, `scratch` has at least 4 bytes of allocated but
981+
// unintialized memory after its last initialized byte, which is where `ptr` points. All
982+
// reachable match arms write `encoded_len` bytes to that region and update the length
983+
// accordingly, and `encoded_len` is always <= 4.
980984
unsafe {
981985
let ptr = scratch.as_mut_ptr().add(scratch.len());
982986

0 commit comments

Comments
 (0)