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 binary marshalling of zero value #253

Merged
merged 2 commits into from Oct 20, 2021
Merged

Conversation

Gilthoniel
Copy link
Contributor

It seems that the recent release has trouble to unmarshal the zero value of the Decimal struct because it is now checking for a correct size of the exponent plus the value while a nil big Int will be encoded with no byte.

Copy link
Member

@mwoss mwoss left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution and for finding this bug! Looks good overall :3

decimal.go Outdated
Comment on lines 1356 to 1357
// Verify we have at least 4 bytes for the exponent. The GOB encoded value
// can be empty.
Copy link
Member

Choose a reason for hiding this comment

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

Just grammar thing. I think may/might would suit better here than can

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, I fixed it.

decimal.go Outdated
if len(data) < 5 {
// Verify we have at least 4 bytes for the exponent. The GOB encoded value
// can be empty.
if len(data) < 4 {
return fmt.Errorf("error decoding binary %v: expected at least 5 bytes, got %d", data, len(data))
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we change this error message to ...expected at least 4 bytes...? :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, that makes a lot of sense ^^'

Copy link
Member

@mwoss mwoss left a comment

Choose a reason for hiding this comment

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

Looks great!

@mwoss mwoss merged commit cd57bf1 into shopspring:master Oct 20, 2021
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