Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix bit shifting bug #365

Merged
merged 1 commit into from
Oct 2, 2018
Merged

Conversation

Nadahar
Copy link
Contributor

@Nadahar Nadahar commented Sep 20, 2018

While running FindBugs on latest master per @kwhopper's request , some warnings unrelated to locale/encoding popped up that I just couldn't ignore.

The reason this code will fail as it is, is that Java defines everything as int (32 bit) by default. As a result, the bits would be "shifted out" and disappear. This should fix it.

@drewnoakes
Copy link
Owner

@Nadahar could you add a unit test that covers the scenario please?

@Nadahar
Copy link
Contributor Author

Nadahar commented Oct 2, 2018

@drewnoakes Done. It was a good thing you asked me though, because the 24 bit left shift needed casting to long as well to avoid turning negative if the leftmost bit is 1.

From what I can see, getLong64() isn't actually used anywhere in your code, which is probably the reason that you never detected this bug.

@drewnoakes drewnoakes merged commit 79de6b0 into drewnoakes:master Oct 2, 2018
@drewnoakes
Copy link
Owner

@Nadahar thanks for following up on this. Good stuff.

@Nadahar Nadahar deleted the BitShiftingBug branch October 2, 2018 17:01
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants