Skip to content

Fix a few endianness bugs on HTTP/2 branch #567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2017

Conversation

rmunn
Copy link
Contributor

@rmunn rmunn commented Jan 19, 2017

  • get31bit now works on both little-endian and big-endian architectures
  • get31bit now explicitly expects its byte[] arg in network byte order
  • stream identifiers now encode correctly
  • poke16 function now writes bytes in network byte order (big-endian)
  • poke32 function now writes bytes in network byte order (big-endian)

Also stripped a few instances of trailing whitespace, in keeping with the project's whitespace policy in its .editorconfig file.

Caution: I have not yet been able to test these changes on a big-endian architecture; I thought that the Raspberry Pi, which uses an ARM chip, would be big-endian, but after downloading and setting up a Raspberry Pi emulator, I discovered that the Pi's chip is bi-endian (able to run in either mode), and is set to little-endian by default. So these changes are untested, but I believe them to be correct.

Certainly the get31bit function should be using &&& 127, not &&& 128, if the goal is to strip the most significant bit and leave the other bits alone. (And it's better to guarantee which byte it's going to be stripping, hence my change to when the checkEndianness call happens). The changes I'm least sure of are the changes to poke16 and poke32. I believe, from what I've read about big-endian architectures, that the byte (n >>> 24) logic will produce the most significant byte on both little- and big-endian architectures, but that's the part I've been unable to test since I haven't yet found a big-endian system to emulate. However, I do believe that it's best if those two functions always poke their bytes into arrays in network byte order, and that's how I wrote them in this patch.

* get31bit now works on both little-endian and big-endian architectures
* get31bit now explicitly expects its byte[] arg in network byte order
* stream identifiers now encode correctly
* poke16 function now writes bytes in network byte order (big-endian)
* poke32 function now writes bytes in network byte order (big-endian)
@ademar ademar merged commit b5280f8 into SuaveIO:feature/http2 Jan 19, 2017
@ademar
Copy link
Member

ademar commented Jan 19, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants