Skip to content
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

Possible bug for logical right shift #6

Merged
merged 2 commits into from
Mar 20, 2016
Merged

Possible bug for logical right shift #6

merged 2 commits into from
Mar 20, 2016

Conversation

sebbsn
Copy link
Contributor

@sebbsn sebbsn commented Mar 17, 2016

When shifting a signed integer n, where n<0, by 31 bits the current return value would result in 0.
This happens because rightShift(int n, int b) is set to return 0 whenever b is greater than 30.
Actually the shift should result in 1, since we see the number as a normal bit sequence when logically shifting, as far as I can conclude from the implementation.
Probably this is not that a big problem, since I did not see this case happen in selfie.c. But it should be considered, for completeness.
If this holds, the same goes for leftShift(int n, int b). When shifting an odd number by 31 bits logically to the left, the result should be INT_MIN, not 0.

@ckirsch ckirsch merged commit ba7d8a5 into cksystemsteaching:master Mar 20, 2016
@ckirsch
Copy link
Member

ckirsch commented Mar 20, 2016

Thanks a lot!

I thought of this case before but then forgot to handle it since I knew that I would never invoke it with b == 31.

I merged your pull request after polishing the code a bit more and fixing leftShift as well.

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.

None yet

2 participants