From 88db3d821abc2da8f81d3204b38debb65b4cd4a0 Mon Sep 17 00:00:00 2001 From: hsu Date: Wed, 24 Aug 2016 15:40:44 -0700 Subject: [PATCH] avoid overflow on 32-bit machines when working with large ns values --- rcl/src/rcl/time_unix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rcl/src/rcl/time_unix.c b/rcl/src/rcl/time_unix.c index 0191f29..7c2e339 100644 --- a/rcl/src/rcl/time_unix.c +++ b/rcl/src/rcl/time_unix.c @@ -66,7 +66,7 @@ rcl_system_time_now(rcl_time_point_value_t * now) RCL_SET_ERROR_MSG("unexpected negative time"); return RCL_RET_ERROR; } - *now = RCL_S_TO_NS(timespec_now.tv_sec) + timespec_now.tv_nsec; + *now = RCL_S_TO_NS((uint64_t)timespec_now.tv_sec) + timespec_now.tv_nsec; return RCL_RET_OK; } @@ -97,7 +97,7 @@ rcl_steady_time_now(rcl_time_point_value_t * now) RCL_SET_ERROR_MSG("unexpected negative time"); return RCL_RET_ERROR; } - *now = RCL_S_TO_NS(timespec_now.tv_sec) + timespec_now.tv_nsec; + *now = RCL_S_TO_NS((uint64_t)timespec_now.tv_sec) + timespec_now.tv_nsec; return RCL_RET_OK; }