From 0a62e9b75d84c39f57cfdf0e80710627fa9091cb Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Tue, 8 Dec 2015 10:33:17 +0100 Subject: [PATCH] src/daemon/utils_time.h: Avoid incorrect rounding in CDTIME_T_TO_TIME{VAL,SPEC}. This change also partially expands CDTIME_T_TO_{US,NS} to avoid dead code warnings in Coverity. Fixes: #1446 CID: 37950, 37951, 37952, 37953, 37954, 41722 --- src/daemon/utils_time.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/daemon/utils_time.h b/src/daemon/utils_time.h index 9e980406..46faa9ce 100644 --- a/src/daemon/utils_time.h +++ b/src/daemon/utils_time.h @@ -68,15 +68,15 @@ extern cdtime_t cdtime_mock; #define CDTIME_T_TO_DOUBLE(t) (((double) (t)) / 1073741824.0) #define DOUBLE_TO_CDTIME_T(d) ((cdtime_t) ((d) * 1073741824.0)) -#define CDTIME_T_TO_TIMEVAL(cdt,tvp) do { \ - (tvp)->tv_sec = CDTIME_T_TO_TIME_T (cdt); \ - (tvp)->tv_usec = (suseconds_t) CDTIME_T_TO_US ((cdt) & 0x3fffffff); \ +#define CDTIME_T_TO_TIMEVAL(cdt,tvp) do { \ + (tvp)->tv_sec = (time_t) ((cdt) >> 30); \ + (tvp)->tv_usec = (suseconds_t) ((((cdt) & 0x3fffffff) * 1000000 + (1 << 29)) >> 30); \ } while (0) #define TIMEVAL_TO_CDTIME_T(tv) US_TO_CDTIME_T(1000000 * (tv)->tv_sec + (tv)->tv_usec) -#define CDTIME_T_TO_TIMESPEC(cdt,tsp) do { \ - (tsp)->tv_sec = CDTIME_T_TO_TIME_T (cdt); \ - (tsp)->tv_nsec = (long) CDTIME_T_TO_NS ((cdt) & 0x3fffffff); \ +#define CDTIME_T_TO_TIMESPEC(cdt,tsp) do { \ + (tsp)->tv_sec = (time_t) ((cdt) >> 30); \ + (tsp)->tv_nsec = (long) ((((cdt) & 0x3fffffff) * 1000000000 + (1 << 29)) >> 30); \ } while (0) #define TIMESPEC_TO_CDTIME_T(ts) NS_TO_CDTIME_T(1000000000ULL * (ts)->tv_sec + (ts)->tv_nsec) -- 2.30.2