From cb53426fa1b1d12c27421ec8ec70ef4fbf5d85e6 Mon Sep 17 00:00:00 2001 From: ritchie Date: Thu, 27 Jul 2023 07:33:46 +0200 Subject: [PATCH] single memset --- src/lib.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e60c8699..f5c5154e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -487,14 +487,10 @@ impl<'de> Deserializer<'de> { unsafe { std::ptr::copy_nonoverlapping(input.as_ptr(), input_buffer.as_mut_ptr(), len); - // ensure we have a 0 to terminate the buffer - std::ptr::write(input_buffer.as_mut_ptr().add(len), 0); - // initialize all remaining bytes - if len < input_buffer.capacity() { - for i in len..input_buffer.capacity() { - std::ptr::write(input_buffer.as_mut_ptr().add(i), 0); - } + // this also ensures we have a 0 to terminate the buffer + for i in len..input_buffer.capacity() { + std::ptr::write(input_buffer.as_mut_ptr().add(i), 0); } // safety: all bytes are initialized