Fix an off by one error which could produce a tv_nsec value of
1'000'000'000. The valid tv_nsec range is [0, 999,999,999], see
https://en.cppreference.com/w/c/chrono/timespec for reference.
Passing a timespec with a tv_nsec value of 1'000'000'000 to
pthread_cond_timedwait has been observed to cause it to return an error
code which in turn makes the DBUS library abort the application when
compiled with asserts enabled (by PTHREAD_CHECK).
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/556
Reviewed-by: Simon McVittie <smcv@collabora.com>
end_time.tv_sec = time_now.tv_sec + timeout_milliseconds / 1000;
end_time.tv_nsec = (time_now.tv_usec + (timeout_milliseconds % 1000) * 1000) * 1000;
- if (end_time.tv_nsec > 1000*1000*1000)
+ if (end_time.tv_nsec >= 1000*1000*1000)
{
end_time.tv_sec += 1;
end_time.tv_nsec -= 1000*1000*1000;