fix delayed_by_us and delayed_by_ms to not return times > at_the_end_of_time (#936)

This commit is contained in:
Graham Sanderson 2022-08-08 07:42:52 -05:00 committed by GitHub
parent 49d7d9edfb
commit fe7849d645
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,8 +95,9 @@ static inline absolute_time_t delayed_by_us(const absolute_time_t t, uint64_t us
absolute_time_t t2;
uint64_t base = to_us_since_boot(t);
uint64_t delayed = base + us;
if (delayed < base) {
delayed = (uint64_t)-1;
if ((int64_t)delayed < 0) {
// absolute_time_t (to allow for signed time deltas) is never greater than INT64_MAX which == at_the_end_of_time
delayed = INT64_MAX;
}
update_us_since_boot(&t2, delayed);
return t2;
@ -113,8 +114,9 @@ static inline absolute_time_t delayed_by_ms(const absolute_time_t t, uint32_t ms
absolute_time_t t2;
uint64_t base = to_us_since_boot(t);
uint64_t delayed = base + ms * 1000ull;
if (delayed < base) {
delayed = (uint64_t)-1;
if ((int64_t)delayed < 0) {
// absolute_time_t (to allow for signed time deltas) is never greater than INT64_MAX which == at_the_end_of_time
delayed = INT64_MAX;
}
update_us_since_boot(&t2, delayed);
return t2;