(Adler32): skip checksum update for zero-length arrays.

This commit is contained in:
morkt 2016-09-14 20:08:13 +04:00
parent 3678e02fec
commit 98d0c47cfb
2 changed files with 9 additions and 2 deletions

View File

@ -114,6 +114,8 @@ namespace GameRes.Utility
public static uint Compute (byte[] buf, int pos, int len) public static uint Compute (byte[] buf, int pos, int len)
{ {
if (0 == len)
return 1;
unsafe unsafe
{ {
fixed (byte* ptr = &buf[pos]) fixed (byte* ptr = &buf[pos])
@ -224,6 +226,8 @@ namespace GameRes.Utility
public void Update (byte[] buf, int pos, int len) public void Update (byte[] buf, int pos, int len)
{ {
if (0 == len)
return;
unsafe unsafe
{ {
fixed (byte* ptr = &buf[pos]) fixed (byte* ptr = &buf[pos])

View File

@ -179,8 +179,11 @@ namespace GameRes.Compression
public override void Write (byte[] buffer, int offset, int count) public override void Write (byte[] buffer, int offset, int count)
{ {
m_adler.Write (buffer, offset, count); if (count > 0)
m_total_in += count; {
m_adler.Write (buffer, offset, count);
m_total_in += count;
}
} }
public override void WriteByte (byte value) public override void WriteByte (byte value)