From da3939cb10356c65d4ecaa378f0b22336c6bbb84 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sat, 6 Sep 2008 09:34:49 +0200 Subject: Fixed a possible integer overflow in GetAbsTime() --- thread.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'thread.c') diff --git a/thread.c b/thread.c index 2d84918d..c9324687 100644 --- a/thread.c +++ b/thread.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.c 1.64 2008/02/15 14:17:42 kls Exp $ + * $Id: thread.c 1.64.1.1 2008/08/16 11:00:40 kls Exp $ */ #include "thread.h" @@ -24,11 +24,12 @@ static bool GetAbsTime(struct timespec *Abstime, int MillisecondsFromNow) { struct timeval now; if (gettimeofday(&now, NULL) == 0) { // get current time - now.tv_usec += MillisecondsFromNow * 1000; // add the timeout - while (now.tv_usec >= 1000000) { // take care of an overflow - now.tv_sec++; - now.tv_usec -= 1000000; - } + now.tv_sec += MillisecondsFromNow / 1000; // add full seconds + now.tv_usec += (MillisecondsFromNow % 1000) * 1000; // add microseconds + if (now.tv_usec >= 1000000) { // take care of an overflow + now.tv_sec++; + now.tv_usec -= 1000000; + } Abstime->tv_sec = now.tv_sec; // seconds Abstime->tv_nsec = now.tv_usec * 1000; // nano seconds return true; -- cgit v1.2.3