px4_poll posix: fix wrap-around for large timeouts

timeout is an int, so it wraps when the poll timeout is >2147ms.
This happened in logger, resulting in poll never returning.
This commit is contained in:
Beat Küng 2019-05-17 11:12:06 +02:00 committed by Daniel Agar
parent 9d8015d029
commit 011aef5464

View File

@ -377,7 +377,7 @@ extern "C" {
// Calculate an absolute time in the future
const unsigned billion = (1000 * 1000 * 1000);
uint64_t nsecs = ts.tv_nsec + (timeout * 1000 * 1000);
uint64_t nsecs = ts.tv_nsec + ((uint64_t)timeout * 1000 * 1000);
ts.tv_sec += nsecs / billion;
nsecs -= (nsecs / billion) * billion;
ts.tv_nsec = nsecs;