Skip to content

Commit

Permalink
Add a safety comment to unsafe block
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Nov 14, 2024
1 parent be2198a commit 73011c0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,10 @@ fn push_wtf8_codepoint(n: u32, scratch: &mut Vec<u8>) {

scratch.reserve(4);

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

Expand Down

0 comments on commit 73011c0

Please sign in to comment.