about summary refs log tree commit diff
path: root/src/libstd/sys/unix/time.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-03-15 15:19:11 -0700
committerAlex Crichton <alex@alexcrichton.com>2016-03-15 15:19:11 -0700
commit0943b1668d9dcf486a77a97d6c28ccd64ffed609 (patch)
treeef04d23bc4679a7aac836b12cf2136d31da275c1 /src/libstd/sys/unix/time.rs
parent1efa752ea694f7ae125cdaf7911ad44b8e6b0e33 (diff)
downloadrust-0943b1668d9dcf486a77a97d6c28ccd64ffed609.tar.gz
rust-0943b1668d9dcf486a77a97d6c28ccd64ffed609.zip
std: Fix overflow when subtracting Instant
This code was currently only exercised on OSX, but this applies the same method
of subtraction used on Linux which doesn't have the same overflow issues.

Note that this currently includes no tests, but that's because this is only
visible with debug assertions enabled. Soon, however, I'll enable debug
assertions on all auto builds on the bots so we should get testing for this.

Closes #32268
Diffstat (limited to 'src/libstd/sys/unix/time.rs')
-rw-r--r--src/libstd/sys/unix/time.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs
index dd248416f84..1444cf31e85 100644
--- a/src/libstd/sys/unix/time.rs
+++ b/src/libstd/sys/unix/time.rs
@@ -88,11 +88,11 @@ mod inner {
                         -> Result<Duration, Duration> {
             if self >= other {
                 Ok(if self.t.tv_usec >= other.t.tv_usec {
-                    Duration::new(self.t.tv_sec as u64 - other.t.tv_sec as u64,
-                                  (self.t.tv_usec as u32 -
-                                   other.t.tv_usec as u32) * 1000)
+                    Duration::new((self.t.tv_sec - other.t.tv_sec) as u64,
+                                  ((self.t.tv_usec -
+                                    other.t.tv_usec) as u32) * 1000)
                 } else {
-                    Duration::new(self.t.tv_sec as u64 - 1 - other.t.tv_sec as u64,
+                    Duration::new((self.t.tv_sec - 1 - other.t.tv_sec) as u64,
                                   (self.t.tv_usec as u32 + (USEC_PER_SEC as u32) -
                                    other.t.tv_usec as u32) * 1000)
                 })