Skip to content

Commit 6631767

Browse files
committed
fix add_100_millis handle different time types
1 parent 46a62b2 commit 6631767

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/tools/miri/tests/pass-dep/libc/libc-time.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,12 @@ mod test_clock_nanosleep {
358358

359359
/// Helper function used to create an instant in the future
360360
fn add_100_millis(mut ts: libc::timespec) -> libc::timespec {
361-
const SECOND: i64 = 1_000_000_000;
361+
// While tv_nsec has type `c_long` tv_sec has type `time_t`. These might
362+
// end up as different types (for example: like i32 and i64).
363+
const SECOND: libc::c_long = 1_000_000_000;
362364
ts.tv_nsec += SECOND / 10;
363365
// If this pushes tv_nsec to SECOND or higher, we need to overflow to tv_sec.
364-
ts.tv_sec += ts.tv_nsec / SECOND;
366+
ts.tv_sec += (ts.tv_nsec / SECOND) as libc::time_t;
365367
ts.tv_nsec %= SECOND;
366368
ts
367369
}
@@ -427,4 +429,3 @@ mod test_clock_nanosleep {
427429
assert!(start_test_sleep.elapsed() > Duration::from_millis(100));
428430
}
429431
}
430-

0 commit comments

Comments
 (0)