Fix some confusions in no-dirty-detection mode
This caused some awful crashes, but doesn't affect any real release builds of waterboxhost
This commit is contained in:
parent
e07944b0f1
commit
27e600c1ac
|
@ -34,6 +34,9 @@ namespace BizHawk.Common
|
||||||
private readonly Stream _stream;
|
private readonly Stream _stream;
|
||||||
public unsafe int Read(Span<byte> buffer)
|
public unsafe int Read(Span<byte> buffer)
|
||||||
{
|
{
|
||||||
|
if (buffer.Length == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (buffer.Length > _buffer.Length)
|
if (buffer.Length > _buffer.Length)
|
||||||
{
|
{
|
||||||
_buffer = new byte[buffer.Length];
|
_buffer = new byte[buffer.Length];
|
||||||
|
@ -48,6 +51,9 @@ namespace BizHawk.Common
|
||||||
|
|
||||||
public unsafe void Write(ReadOnlySpan<byte> buffer)
|
public unsafe void Write(ReadOnlySpan<byte> buffer)
|
||||||
{
|
{
|
||||||
|
if (buffer.Length == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (buffer.Length > _buffer.Length)
|
if (buffer.Length > _buffer.Length)
|
||||||
{
|
{
|
||||||
_buffer = new byte[buffer.Length];
|
_buffer = new byte[buffer.Length];
|
||||||
|
|
|
@ -817,13 +817,14 @@ impl MemoryBlock {
|
||||||
|
|
||||||
self.refresh_all_protections();
|
self.refresh_all_protections();
|
||||||
self.sealed = true;
|
self.sealed = true;
|
||||||
#[cfg(not(feature = "no-dirty-detection"))]
|
|
||||||
{
|
|
||||||
use sha2::{Sha256, Digest};
|
|
||||||
|
|
||||||
|
use sha2::{Sha256, Digest};
|
||||||
self.hash = {
|
self.hash = {
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
bin::write(&mut hasher, &self.addr).unwrap();
|
bin::write(&mut hasher, &self.addr).unwrap();
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no-dirty-detection"))]
|
||||||
|
{
|
||||||
for p in self.pages.iter() {
|
for p in self.pages.iter() {
|
||||||
match &p.snapshot {
|
match &p.snapshot {
|
||||||
Snapshot::None => bin::writeval(&mut hasher, 1).unwrap(),
|
Snapshot::None => bin::writeval(&mut hasher, 1).unwrap(),
|
||||||
|
@ -831,9 +832,10 @@ impl MemoryBlock {
|
||||||
Snapshot::Data(d) => { hasher.write(d.slice()).unwrap(); },
|
Snapshot::Data(d) => { hasher.write(d.slice()).unwrap(); },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
hasher.finalize()[..].to_owned()
|
hasher.finalize()[..].to_owned()
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue