summaryrefslogtreecommitdiff
path: root/rts/posix/Select.c
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2012-07-31 09:06:43 +0100
committerSimon Marlow <marlowsd@gmail.com>2012-07-31 09:19:29 +0100
commit598ee1ad1b8de089a2ed207543761d617a90db52 (patch)
tree76403dd8740587db6cc70a229d067e76e74fb6af /rts/posix/Select.c
parent9e7acbe7ef2094b301ffcf0b0e7f1fa80abc8460 (diff)
downloadhaskell-598ee1ad1b8de089a2ed207543761d617a90db52.tar.gz
Fix #7087 (integer overflow in getDelayTarget())
Diffstat (limited to 'rts/posix/Select.c')
-rw-r--r--rts/posix/Select.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/rts/posix/Select.c b/rts/posix/Select.c
index 5acb8174da..99a9508507 100644
--- a/rts/posix/Select.c
+++ b/rts/posix/Select.c
@@ -67,9 +67,18 @@ static LowResTime getLowResTimeOfDay(void)
*/
LowResTime getDelayTarget (HsInt us)
{
- // round up the target time, because we never want to sleep *less*
- // than the desired amount.
- return TimeToLowResTimeRoundUp(getProcessElapsedTime() + USToTime(us));
+ Time elapsed;
+ elapsed = getProcessElapsedTime();
+
+ // If the desired target would be larger than the maximum Time,
+ // default to the maximum Time. (#7087)
+ if (us > TimeToUS(TIME_MAX - elapsed)) {
+ return TimeToLowResTimeRoundDown(TIME_MAX);
+ } else {
+ // round up the target time, because we never want to sleep *less*
+ // than the desired amount.
+ return TimeToLowResTimeRoundUp(elapsed + USToTime(us));
+ }
}
/* There's a clever trick here to avoid problems when the time wraps