- tv->tv_usec += 1000 * msec;
- if (tv->tv_usec >= 1000000) {
- tv->tv_usec -= 1000000;
- tv->tv_sec++;
+ uint64_t adj_nsec = 1000000ULL * msec;
+
+ ts->tv_nsec += adj_nsec;
+ if (adj_nsec >= 1000000000) {
+ uint64_t adj_sec = adj_nsec / 1000000000;
+
+ ts->tv_nsec -= adj_sec * 1000000000;
+ ts->tv_sec += adj_sec;
+ }
+ if (ts->tv_nsec >= 1000000000){
+ ts->tv_nsec -= 1000000000;
+ ts->tv_sec++;