Closed lopopolo closed 1 year ago
This is certainly not the intended behavior. I'll add overflow checks to the necessary methods. The reason I did not originally opt for returning a Result
is because the time spans are beyond large (as in longer than the age of the universe), so there is no reason anyone should even be remotely close to the bound.
Fixed on main.
Thanks for merging a fix @jhpratt 💯
I took a peek at the commit and left a few comments / questions: https://github.com/time-rs/time/commit/5efea65d2e50c09e3990332511aff317fd42747e
I think there is still some unexpected behavior in these constructors around NAN and infinite floats.
How about use u64 instead of i64?
@Cheban1996 That wouldn't change anything, not to mention that Duration
is a signed type.
Duration
has several constructors that perform unchecked signed multiplication, which can result in panics in debug mode and unexpected wrapping in release.I don't have a need to these inputs into
Duration
constructors but I found this unexpected given the pervasiveness of checked operations in the public API.Playground link: https://play.rust-lang.org/?version=stable&mode=release&edition=2021&gist=731f151589796275ac9c7678ec43a709
Code:
Output: