From 3815ccae8b6383c9804739472afddf65ec793da7 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Mon, 14 Mar 2011 14:30:44 +0100 Subject: [PATCH] [lib] Fix timestamp_to_ms() owl_timestamp_to_ms() did not convert properly the result to uint64_t. This is now fixed, but time functions are still buggy, as we do not take into account the length of tv_sec (owl_timestamp_round_to_ms() assumes that it is 9-digit long). --- libowlps/libowlps.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libowlps/libowlps.c b/libowlps/libowlps.c index a8cb571..b1f3ae5 100644 --- a/libowlps/libowlps.c +++ b/libowlps/libowlps.c @@ -126,7 +126,7 @@ int owl_timestamp_now_ns(TIMESTAMP *now) */ void owl_timestamp_round_to_ms(TIMESTAMP *now) { - now->tv_nsec = now->tv_nsec / 1000000 * 1000000 ; + now->tv_nsec = now->tv_nsec / 1000000u * 1000000u ; } @@ -151,7 +151,7 @@ TIMESTAMP owl_timeval_to_timestamp(const struct timeval d) { TIMESTAMP res ; res.tv_sec = d.tv_sec ; - res.tv_nsec = d.tv_usec * 1000 ; + res.tv_nsec = d.tv_usec * 1000u ; return res ; } @@ -162,7 +162,7 @@ TIMESTAMP owl_timeval_to_timestamp(const struct timeval d) */ uint64_t owl_timestamp_to_ms(TIMESTAMP d) { - return d.tv_sec * 1000 + d.tv_nsec / 1000000 ; + return (uint64_t) d.tv_sec * 1000u + (uint64_t) d.tv_nsec / 1000000u ; }