diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2008-09-06 09:41:15 +0200 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2008-09-06 09:41:15 +0200 |
commit | 2e66fdd634b7490100e0ed9e72c84c487ef5ab14 (patch) | |
tree | 15d364e8f6209c00f84db861d2220284e87720df /thread.c | |
parent | 248b7424befc96e5b4d8ff28dc21b329c3f7240c (diff) | |
download | vdr-2e66fdd634b7490100e0ed9e72c84c487ef5ab14.tar.gz vdr-2e66fdd634b7490100e0ed9e72c84c487ef5ab14.tar.bz2 |
Fixed a possible integer overflow in GetAbsTime()
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.c 2.1 2008/04/13 11:53:56 kls Exp $ + * $Id: thread.c 2.2 2008/09/06 09:39:43 kls Exp $ */ #include "thread.h" @@ -25,11 +25,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; |