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

Remove usage of try_into().unwrap() where feasible #89

Open
xoloki opened this issue Sep 26, 2024 · 0 comments · May be fixed by #91
Open

Remove usage of try_into().unwrap() where feasible #89

xoloki opened this issue Sep 26, 2024 · 0 comments · May be fixed by #91
Assignees

Comments

@xoloki
Copy link
Collaborator

xoloki commented Sep 26, 2024

Early versions of wsts used usize types anywhere that the code would deal with the size of memory. But this is problematic when sending data over the network, since usize is a platform dependent type.

So at some point we changed all public integer types to be fixed size, i.e. u32 or u64. This required sprinkling as usize casts where needed. However, @jferrant discovered that as usize casts will fail silently if the cast value is improperly sized.

As a result, we now call try_into().unwrap() to handle all casts between u32/u64 and usize. The logic was that while these can fail, they are extremely unlikely to do so, and if they do it's likely a result of a misconfiguration that should be noticed and fixed.

However, since this is library code, it is bad form to ever panic when an error could be returned instead. So this issue will track work to remove these unwrap calls whenever feasible.

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 a pull request may close this issue.

1 participant