diff --git a/src/BizHawk.Common/SpanStream.cs b/src/BizHawk.Common/SpanStream.cs index a05bb35721..08401cdca2 100644 --- a/src/BizHawk.Common/SpanStream.cs +++ b/src/BizHawk.Common/SpanStream.cs @@ -34,6 +34,9 @@ namespace BizHawk.Common private readonly Stream _stream; public unsafe int Read(Span buffer) { + if (buffer.Length == 0) + return 0; + if (buffer.Length > _buffer.Length) { _buffer = new byte[buffer.Length]; @@ -48,6 +51,9 @@ namespace BizHawk.Common public unsafe void Write(ReadOnlySpan buffer) { + if (buffer.Length == 0) + return; + if (buffer.Length > _buffer.Length) { _buffer = new byte[buffer.Length]; diff --git a/waterbox/waterboxhost/src/memory_block/mod.rs b/waterbox/waterboxhost/src/memory_block/mod.rs index 44ed2ebf73..04fdd2cbc7 100644 --- a/waterbox/waterboxhost/src/memory_block/mod.rs +++ b/waterbox/waterboxhost/src/memory_block/mod.rs @@ -817,13 +817,14 @@ impl MemoryBlock { self.refresh_all_protections(); self.sealed = true; - #[cfg(not(feature = "no-dirty-detection"))] - { - use sha2::{Sha256, Digest}; - self.hash = { - let mut hasher = Sha256::new(); - bin::write(&mut hasher, &self.addr).unwrap(); + use sha2::{Sha256, Digest}; + self.hash = { + let mut hasher = Sha256::new(); + bin::write(&mut hasher, &self.addr).unwrap(); + + #[cfg(not(feature = "no-dirty-detection"))] + { for p in self.pages.iter() { match &p.snapshot { Snapshot::None => bin::writeval(&mut hasher, 1).unwrap(), @@ -831,9 +832,10 @@ impl MemoryBlock { Snapshot::Data(d) => { hasher.write(d.slice()).unwrap(); }, } } - hasher.finalize()[..].to_owned() - }; - } + } + + hasher.finalize()[..].to_owned() + }; Ok(()) }