* [LTP] [PATCH] include/tst_timer.h: Fix overflows
@ 2021-01-15 15:19 Cyril Hrubis
2021-01-18 10:42 ` Petr Vorel
0 siblings, 1 reply; 3+ messages in thread
From: Cyril Hrubis @ 2021-01-15 15:19 UTC (permalink / raw)
To: ltp
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.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
---
include/tst_timer.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/tst_timer.h b/include/tst_timer.h
index 657c0824f..4a79ae208 100644
--- a/include/tst_timer.h
+++ b/include/tst_timer.h
@@ -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;
}
/*
--
2.26.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [LTP] [PATCH] include/tst_timer.h: Fix overflows
2021-01-15 15:19 [LTP] [PATCH] include/tst_timer.h: Fix overflows Cyril Hrubis
@ 2021-01-18 10:42 ` Petr Vorel
2021-01-18 12:21 ` Cyril Hrubis
0 siblings, 1 reply; 3+ messages in thread
From: Petr Vorel @ 2021-01-18 10:42 UTC (permalink / raw)
To: ltp
Hi Cyril,
> 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.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
^ permalink raw reply [flat|nested] 3+ messages in thread
* [LTP] [PATCH] include/tst_timer.h: Fix overflows
2021-01-18 10:42 ` Petr Vorel
@ 2021-01-18 12:21 ` Cyril Hrubis
0 siblings, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2021-01-18 12:21 UTC (permalink / raw)
To: ltp
Hi!
Pushed, thanks.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-18 12:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-15 15:19 [LTP] [PATCH] include/tst_timer.h: Fix overflows Cyril Hrubis
2021-01-18 10:42 ` Petr Vorel
2021-01-18 12:21 ` Cyril Hrubis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.