From 5fe6c528f3a6aca0a70b09b34fa26b86e6494739 Mon Sep 17 00:00:00 2001 From: Mikael Arguedas Date: Fri, 4 Nov 2016 10:59:44 -0700 Subject: [PATCH] cast time at macro expansion (#86) --- rcl/include/rcl/time.h | 6 +++--- rcl/src/rcl/time_unix.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rcl/include/rcl/time.h b/rcl/include/rcl/time.h index edf990e..d013cdc 100644 --- a/rcl/include/rcl/time.h +++ b/rcl/include/rcl/time.h @@ -24,9 +24,9 @@ extern "C" #include "rcl/types.h" #include "rcl/visibility_control.h" -#define RCL_S_TO_NS(seconds) (seconds * (1000 * 1000 * 1000)) -#define RCL_MS_TO_NS(milliseconds) (milliseconds * (1000 * 1000)) -#define RCL_US_TO_NS(microseconds) (microseconds * 1000) +#define RCL_S_TO_NS(seconds) ((int64_t)seconds * (1000 * 1000 * 1000)) +#define RCL_MS_TO_NS(milliseconds) ((int64_t)milliseconds * (1000 * 1000)) +#define RCL_US_TO_NS(microseconds) ((int64_t)microseconds * 1000) #define RCL_NS_TO_S(nanoseconds) (nanoseconds / (1000 * 1000 * 1000)) #define RCL_NS_TO_MS(nanoseconds) (nanoseconds / (1000 * 1000)) diff --git a/rcl/src/rcl/time_unix.c b/rcl/src/rcl/time_unix.c index 7c2e339..0191f29 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((uint64_t)timespec_now.tv_sec) + timespec_now.tv_nsec; + *now = RCL_S_TO_NS(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((uint64_t)timespec_now.tv_sec) + timespec_now.tv_nsec; + *now = RCL_S_TO_NS(timespec_now.tv_sec) + timespec_now.tv_nsec; return RCL_RET_OK; }