bnum
bnum copied to clipboard
Overflow behaviour
This crate currently panics in debug mode and wraps in release mode, which is by default the same behaviour as Rust's primitives.
However, it is not affected by overflow-checks = true
.
Some context: We are using this crate as a dependency for the math types in cosmwasm-std and care a lot about avoiding overflows (which is also why we recommend all our users to enable overflow-checks). We recently mistakenly used the non-checked version of some operations, leading to potential overflows, even though we had tests in place to guard against that (but those didn't fail because they run in debug mode by default). If overflow-checks worked for this crate, that would have made this much less severe.
Long story short: I am wondering if you see some way to make the overflow behaviour less error-prone. Would it make sense to default to panicing operations? Or maybe it is more in the spirit of this crate to detect the overflow-checks flag? I found this somewhat hacky method of detecting the flag. Would love to hear your thoughts on this.