Skip to content

Commit

Permalink
appease miri
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Oct 24, 2023
1 parent 2d36ec0 commit 616aa18
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions capnp/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,11 +927,16 @@ unsafe impl<'a> Allocator for SingleSegmentAllocator<'a> {
}

unsafe fn deallocate_segment(&mut self, ptr: *mut u8, _word_size: u32, words_used: u32) {
if ptr == self.segment.as_mut_ptr() {
let seg_ptr = self.segment.as_mut_ptr();
if ptr == seg_ptr {
// Rezero the slice to allow reuse of the allocator. We only need to write
// words that we know might contain nonzero values.
unsafe {
core::ptr::write_bytes(ptr, 0u8, (words_used as usize) * BYTES_PER_WORD);
core::ptr::write_bytes(
seg_ptr, // miri isn't happy if we use ptr instead
0u8,
(words_used as usize) * BYTES_PER_WORD,
);
}
self.segment_allocated = false;
}
Expand Down

0 comments on commit 616aa18

Please sign in to comment.