Files
rust/src/libstd
bors 6acbb5b65c Auto merge of #55527 - sgeisler:time-checked-add, r=sfackler
Implement checked_add_duration for SystemTime

[Original discussion on the rust user forum](https://users.rust-lang.org/t/std-systemtime-misses-a-checked-add-function/21785)

Since `SystemTime` is opaque there is no way to check if the result of an addition will be in bounds. That makes the `Add<Duration>` trait completely unusable with untrusted data. This is a big problem because adding a `Duration` to `UNIX_EPOCH` is the standard way of constructing a `SystemTime` from a unix timestamp.

This PR implements `checked_add_duration(&self, &Duration) -> Option<SystemTime>` for `std::time::SystemTime` and as a prerequisite also for all platform specific time structs. This also led to the refactoring of many `add_duration(&self, &Duration) -> SystemTime` functions to avoid redundancy (they now unwrap the result of `checked_add_duration`).

Some basic unit tests for the newly introduced function were added too.

I wasn't sure which stabilization attribute to add to the newly introduced function, so I just chose `#[stable(feature = "time_checked_add", since = "1.32.0")]` for now to make it compile. Please let me know how I should change it or if I violated any other conventions.

P.S.: I could only test on Linux so far, so I don't necessarily expect it to compile for all platforms.
2018-11-25 19:01:35 +00:00
..
2018-09-04 13:22:08 -06:00
2018-11-13 14:45:31 -05:00
2018-07-30 18:18:23 +02:00
2018-11-11 09:22:28 -08:00
2018-10-24 15:19:23 -07:00
2018-10-24 15:19:23 -07:00
2018-09-19 15:01:19 -07:00
2018-11-21 06:50:17 -05:00
2018-11-21 06:50:17 -05:00
2018-08-19 17:41:28 +02:00
2018-05-16 19:11:31 +02:00
2018-11-05 18:54:17 +02:00
2018-11-21 06:50:17 -05:00
2018-07-10 20:35:36 +02:00