diff options
Diffstat (limited to 'runtime/base/time_utils.cc')
| -rw-r--r-- | runtime/base/time_utils.cc | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/runtime/base/time_utils.cc b/runtime/base/time_utils.cc index b7cf2072dc..3e5bac8486 100644 --- a/runtime/base/time_utils.cc +++ b/runtime/base/time_utils.cc @@ -15,6 +15,7 @@ */ #include <inttypes.h> +#include <limits> #include <sstream> #include "time_utils.h" @@ -190,9 +191,16 @@ void InitTimeSpec(bool absolute, int clock, int64_t ms, int32_t ns, timespec* ts } 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; |