void tv_scale(const unsigned long mult, const struct timeval *tv,
struct timeval *result)
{
- result->tv_sec = mult * tv->tv_sec;
- result->tv_sec += tv->tv_usec * mult / 1000 / 1000;
- result->tv_usec = tv->tv_usec * mult % (1000 * 1000);
+ uint64_t x = ((uint64_t)tv->tv_sec * 1000 * 1000 + tv->tv_usec) * mult;
+
+ result->tv_sec = x / 1000 / 1000;
+ result->tv_usec = x % (1000 * 1000);
}
/**