-
Notifications
You must be signed in to change notification settings - Fork 188
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
Conversation
There was a problem hiding this 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.
@cuviper Formatted it. Yhea, could be something to fuzz even. |
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! |
bors r+ |
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>
Build succeeded |
I published 0.2.2 -- thanks again! |
@cuviper Thanks for the super fast turnaround on this one! |
The trick for saving a byte on
0x800000..
only works for negative numbers. This caused +128 to be serialized as0x80
which is -128. So pretty bad bug.