[PATCH rtems-libbsd v4 06/19] rtemsbsd: Catch timeout overflows
chrisj at rtems.org
chrisj at rtems.org
Wed Aug 4 08:53:16 UTC 2021
From: Chris Johns <chrisj at rtems.org>
Update #4475
---
rtemsbsd/rtems/rtems-kernel-timesupport.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/rtemsbsd/rtems/rtems-kernel-timesupport.c b/rtemsbsd/rtems/rtems-kernel-timesupport.c
index ef14d1fa..bc2e7b9f 100644
--- a/rtemsbsd/rtems/rtems-kernel-timesupport.c
+++ b/rtemsbsd/rtems/rtems-kernel-timesupport.c
@@ -37,6 +37,7 @@
#include <sys/time.h>
+#include <limits.h>
#include <rtems/score/timespec.h>
/*
@@ -45,10 +46,15 @@
int
tvtohz(struct timeval *tv)
{
- struct timespec ts;
+ struct timespec ts;
+ uint32_t ticks;
- ts.tv_sec = tv->tv_sec;
- ts.tv_nsec = tv->tv_usec * 1000;
+ ts.tv_sec = tv->tv_sec;
+ ts.tv_nsec = tv->tv_usec * 1000;
- return (int) _Timespec_To_ticks( &ts );
+ ticks = _Timespec_To_ticks(&ts);
+ if (ticks > INT_MAX)
+ ticks = INT_MAX;
+
+ return ticks;
}
--
2.24.1
More information about the devel
mailing list