Skip to content

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

Merged
bors[bot] merged 3 commits into
rust-num:masterfrom
leoyvens:fix-to-signed-bytes
Dec 14, 2018
Merged

bors[bot] merged 3 commits into
rust-num:masterfrom
leoyvens:fix-to-signed-bytes

Conversation

@leoyvens

Copy link
Copy Markdown
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.

@cuviper cuviper left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor Author

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

@cuviper

cuviper commented Dec 14, 2018

Copy link
Copy Markdown
Member

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

cuviper commented Dec 14, 2018

Copy link
Copy Markdown
Member

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

bors Bot commented Dec 14, 2018

Copy link
Copy Markdown
Contributor

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

cuviper commented Dec 14, 2018

Copy link
Copy Markdown
Member

I published 0.2.2 -- thanks again!

@leoyvens

Copy link
Copy Markdown
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