lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] fix for Timer::inspect() on POSIX platforms


From: Vaclav Slavik
Subject: [lmi] fix for Timer::inspect() on POSIX platforms
Date: Wed, 17 Dec 2008 00:11:04 +0100

Hi,

please apply the following (or equivalent; I preferred explicit cast to
simply appending ".0" as it makes it more clear why is it done) patch:

Index: timer.cpp
===================================================================
RCS file: /sources/lmi/lmi/timer.cpp,v
retrieving revision 1.14
diff -u -u -r1.14 timer.cpp
--- timer.cpp   19 Jun 2008 13:39:16 -0000      1.14
+++ timer.cpp   16 Dec 2008 23:01:54 -0000
@@ -165,7 +165,7 @@
 #if defined LMI_POSIX
     timeval x;
     gettimeofday(&x, 0);
-    return 1000000 * x.tv_sec + x.tv_usec;
+    return elapsed_t(1000000) * x.tv_sec + x.tv_usec;
 #elif defined LMI_MSW
 #   ifdef LMI_MS_HEADER_INCLUDED
     LARGE_INTEGER z;

This deserves some explanation: on POSIX, elapsed_t is double and the
value is microseconds since the Epoch, i.e. a really large value that
doesn't fit into long int on x86/x86_64. Without the cast, the "1000000
* x.tv_sec + x.tv_usec" expression is evaluated as integer one and
overflows.

Vaclav





reply via email to

[Prev in Thread] Current Thread [Next in Thread]