include/tst_timer.h: Fix overflows
PATCH 1/1 include/tst_timer.h: Fix overflows
This fixes overflows in tst_timeval_to_us() and tst_timeval_to_ns() on 32bit hardware. We have to cast the tv_sec (ulong) to (long long) explicitly otherwise the tv_sec will overflow the multiplication.
This fixes clock_gettime04 where the overflow corrupted the result from gettimeofday() when it was converted from timeval to timespec.
--- include/tst_timer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/tst_timer.h +2 -2
@@ -26,7 +26,7 @@*/ static inline long long tst_timeval_to_us (struct timeval t) { -return t.tv_sec *1000000 + t.tv_usec; +return ((long long )t.tv_sec) *1000000 + t.tv_usec; }/*
@@ -34,7 +34,7 @@ static inline long long tst_timeval_to_us(struct timeval t)*/ static inline long long tst_timeval_to_ms (struct timeval t) { -return t.tv_sec *1000 + (t.tv_usec +500 ) /1000 ; +return ((long long )t.tv_sec) *1000 + (t.tv_usec +500 ) /1000 ; }/*
Signature · 1 line
2.26.2
PATCH 1/1 include/tst_timer.h: Fix overflows
Hi Cyril,
Quoted 6 lines
This fixes overflows in
tst_timeval_to_us()andtst_timeval_to_ns()on 32bit hardware. We have to cast thetv_sec(ulong) to (long long) explicitly otherwise thetv_secwill overflow the multiplication.This fixes
clock_gettime04where the overflow corrupted the result fromgettimeofday()when it was converted from timeval to timespec.
Kind regards,
Petr
PATCH 1/1 include/tst_timer.h: Fix overflows
Hi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]