*/
#include <inttypes.h>
+#include <limits>
#include <sstream>
#include "time_utils.h"
}
int64_t end_sec = ts->tv_sec + ms / 1000;
- if (UNLIKELY(end_sec >= 0x7fffffff)) {
- LOG(INFO) << "Note: end time exceeds INT32_MAX: " << end_sec;
- end_sec = 0x7ffffffe;
+ constexpr int32_t int32_max = std::numeric_limits<int32_t>::max();
+ if (UNLIKELY(end_sec >= int32_max)) {
+ // Either ms was intended to denote an infinite timeout, or we have a
+ // problem. The former generally uses the largest possible millisecond
+ // or nanosecond value. Log only in the latter case.
+ constexpr int64_t int64_max = std::numeric_limits<int64_t>::max();
+ if (ms != int64_max && ms != int64_max / (1000 * 1000)) {
+ LOG(INFO) << "Note: end time exceeds INT32_MAX: " << end_sec;
+ }
+ end_sec = int32_max - 1; // Allow for increment below.
}
ts->tv_sec = end_sec;
ts->tv_nsec = (ts->tv_nsec + (ms % 1000) * 1000000) + ns;