Skip to content

Makes zigzag encoding and decoding save wrt. undefined behavior, see #28 #35

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

Closed

Conversation

daniel-j-h
Copy link
Contributor

This changes the zigzag encoding and decoding implementation so that we never run into undefined behavior with signed integer overflows. See thread starting at #28 (comment) cc @lemire

@@ -2,7 +2,7 @@

static inline
uint32_t _zigzag_encode_32 (int32_t val) {
return (val + val) ^ (val >> 31);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signed val + val here is the issue wrt. overflow causing undefined behavior

@lemire
Copy link
Member

lemire commented Jul 5, 2021

Please see PR #36

@lemire
Copy link
Member

lemire commented Jul 5, 2021

Closing in favour of #36

@lemire lemire closed this Jul 5, 2021
@daniel-j-h daniel-j-h deleted the zigzag-integer-overflow branch July 6, 2021 07:22
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