From 35e2f73832e187e0d436ffe04e80b9f0d49b31c3 Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Mon, 23 Oct 2023 20:11:57 -0400 Subject: [PATCH] add tests for other allocators --- capnp/src/message.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/capnp/src/message.rs b/capnp/src/message.rs index d67e496a4..9333dd859 100644 --- a/capnp/src/message.rs +++ b/capnp/src/message.rs @@ -849,11 +849,16 @@ unsafe impl<'a> Allocator for ScratchSpaceHeapAllocator<'a> { } unsafe fn deallocate_segment(&mut self, ptr: *mut u8, word_size: u32, words_used: u32) { - if ptr == self.scratch_space.as_mut_ptr() { + let seg_ptr = self.scratch_space.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.scratch_space_allocated = false; } else {