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

Fix to_signed_bytes_* for positive number with leading 0x80 #72

Merged
merged 3 commits into from
Dec 14, 2018
Merged

Fix to_signed_bytes_* for positive number with leading 0x80 #72

merged 3 commits into from
Dec 14, 2018

Conversation

leoyvens
Copy link
Contributor

The trick for saving a byte on 0x800000.. only works for negative numbers. This caused +128 to be serialized as 0x80 which is -128. So pretty bad bug.

Copy link
Member

@cuviper cuviper left a comment

Choose a reason for hiding this comment

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

Ouch, nice catch! Can you just rustfmt this to wrap the long lines?

(musing) It might be good to have a test on the round trip to/from signed bytes, sweeping a decent range of numbers. Something like 0..u16::MAX plus a few more to get into 3 bytes, then both positive and negative.

@leoyvens
Copy link
Contributor Author

@cuviper Formatted it. Yhea, could be something to fuzz even.

@cuviper
Copy link
Member

cuviper commented Dec 14, 2018

I've got that round trip test written that also shows your failure. I'll push it here in a moment.

Fuzzing num-bigint would be awesome across the board!

@cuviper
Copy link
Member

cuviper commented Dec 14, 2018

bors r+

bors bot added a commit that referenced this pull request Dec 14, 2018
72: Fix `to_signed_bytes_*` for positive number with leading `0x80` r=cuviper a=leodasvacas

The trick for saving a byte on `0x800000..` only works for negative numbers. This caused +128 to be serialized as `0x80` which is -128. So pretty bad bug.

Co-authored-by: Leonardo Yvens Schwarzstein <leoyvens@gmail.com>
Co-authored-by: Josh Stone <cuviper@gmail.com>
@bors
Copy link
Contributor

bors bot commented Dec 14, 2018

Build succeeded

@bors bors bot merged commit 732e8e7 into rust-num:master Dec 14, 2018
@leoyvens leoyvens deleted the fix-to-signed-bytes branch December 14, 2018 21:07
@cuviper
Copy link
Member

cuviper commented Dec 14, 2018

I published 0.2.2 -- thanks again!

@leoyvens
Copy link
Contributor Author

@cuviper Thanks for the super fast turnaround on this one!

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