Skip to content

Commit

Permalink
Merge pull request #1213 from djmitche/safety-comment
Browse files Browse the repository at this point in the history
Add a safety comment to unsafe block
  • Loading branch information
dtolnay authored Nov 15, 2024
2 parents be2198a + 73011c0 commit 75ed447
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 75ed447

Please sign in to comment.