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

Make it impossible to accidentally use an uninitialized Digest #65

Open
cespare opened this issue Oct 19, 2021 · 0 comments
Open

Make it impossible to accidentally use an uninitialized Digest #65

cespare opened this issue Oct 19, 2021 · 0 comments

Comments

@cespare
Copy link
Owner

cespare commented Oct 19, 2021

I noticed a sharp edge of the API. It's tempting (especially if xxhash.Digest is embedded in a larger structure) to do this:

var d xxhash.Digest
... d.Write(...) ...
h := d.Sum64()

But this is broken: the zero value of Digest is not usable. You must call Reset first.

We should fix this, either by making the incorrect usage crash or by automatically calling Reset when an uninitialized Digest is used. Hopefully the branch is very predictable and doesn't add much cost.

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

No branches or pull requests

1 participant