Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

SharpDX.DataStream.ReadByte() not working properly for byte range 0xf0...0xff #268

Closed
elgonzo opened this issue Feb 4, 2014 · 1 comment

Comments

@elgonzo
Copy link

elgonzo commented Feb 4, 2014

According to MSDN documentation for System.IO.Stream.ReadByte(), the return value should be an unsigned byte cast to an Int32, or -1 if at the end of the stream.

However, the DataStream.ReadByte() is casting a signed byte to an Int32, which makes it produce wrong return values for bytes in the range of 0xf0...0xff.

Especially, a 0xff byte will be returned as -1 (instead of 255, as it should be) and thus incorrectly indicate end of stream.

To fix this bug, cast the result explicitly as a byte when returning, like:

return  (byte)  _buffer[_position++];
@xoofx
Copy link
Member

xoofx commented Feb 4, 2014

Thanks for the report, this is fixed by commit aa1e9e2

@xoofx xoofx closed this as completed Feb 4, 2014
xoofx added a commit that referenced this issue Feb 4, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants