vinothr / libjingle

Automatically exported from code.google.com/p/libjingle
0 stars 0 forks source link

Time() wrap-around: uint32 is not enough to store milliseconds starting from 1970 #167

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
// If that was fixed already than please disregard

time.cc has the code like:

#include <sys/time.h>

uint32 Time() {
  struct timeval tv;
  gettimeofday(&tv, 0);
  return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}

Caused me a bug at the point of wrap-around happening approx. once in 49 days. 
All functions in this module have to use uint64. My code is using a really long 
timeout of 24 hrs = 60 sec * 60 min * 24 hrs * 1000 and that in combination 
with the "current time" closer to 0xFFFFFFFF than 24 hrs in ms was causing a 
fabulous effect. ;-)

The rest of functions in this modules have to be fixed too.

Original issue reported on code.google.com by alexande...@gmail.com on 17 May 2011 at 11:27

GoogleCodeExporter commented 9 years ago

Original comment by juberti@google.com on 31 May 2013 at 8:32