Skip to content

Commit f9f212d

Browse files
committed
[Concurrency] Prevent negative sleeps from sleeping forever.
Requests to sleep until a negative timestamp would result in sleeping until `UINT64_MAX` nanoseconds from the start of the relevant clock, which is about 585 years. rdar://154346018
1 parent ef934e0 commit f9f212d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

stdlib/public/Concurrency/DispatchGlobalExecutor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ platform_time(uint64_t nsec) {
300300
static inline dispatch_time_t
301301
clock_and_value_to_time(int clock, long long sec, long long nsec) {
302302
uint64_t deadline;
303-
if (__builtin_mul_overflow(sec, NSEC_PER_SEC, &deadline)
303+
if (sec < 0 || sec == 0 && nsec < 0)
304+
deadline = 0;
305+
else if (__builtin_mul_overflow(sec, NSEC_PER_SEC, &deadline)
304306
|| __builtin_add_overflow(nsec, deadline, &deadline)) {
305307
deadline = UINT64_MAX;
306308
}

0 commit comments

Comments
 (0)