Be.IO icon indicating copy to clipboard operation
Be.IO copied to clipboard

Fix ReadBoolean and ReadSByte reading wrong buffer

Open klotztech opened this issue 7 years ago • 0 comments

Fixes #3.

Explanation

From the reference source implementation of BinaryReader:

public virtual bool ReadBoolean(){
    FillBuffer(1);
    return (m_buffer[0]!=0);
}
public virtual sbyte ReadSByte() {
    FillBuffer(1);
    return (sbyte)(m_buffer[0]);
}

These two functions first call the FillBuffer(int numBytes) method, which is overloaded by BeBinaryReader and therefore reads the specified amount of bytes into it's own protected field aka. buffer instead of the private field m_buffer that BinaryReader uses and which is also read by the afore mentioned read methods, causing them to fail silently (reading a zero-byte from the empty but still allocated m_buffer).

I've re-implemented these methods in BeBinaryReader, so that they the buffer field instead. The BeBinaryWriter implementation doesn't seem to be affected by this problem.

Hope this helps!

klotztech avatar Aug 19 '18 21:08 klotztech