Skip to content

Commit 98bbca2

Browse files
committed
fix(util):1.12.4
1. 修复GetUtcMilliseconds()与GetUtcMicroseconds()在32位嵌入式平台上出现数值溢出问题; 2. 在tools/下添加了实时渲染Graphviz的python工具
1 parent 4ddcfec commit 98bbca2

File tree

5 files changed

+384
-5
lines changed

5 files changed

+384
-5
lines changed

modules/util/timestamp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ uint64_t GetUtcMilliseconds()
4545
if (gettimeofday(&tv, &tz) != 0)
4646
return 0;
4747

48-
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
48+
return static_cast<uint64_t>(tv.tv_sec) * 1000 + tv.tv_usec / 1000;
4949
}
5050

5151
uint64_t GetCurrentMillisecondsFrom1970() { return GetUtcMilliseconds(); }
@@ -58,12 +58,12 @@ uint64_t GetUtcMicroseconds()
5858
if (gettimeofday(&tv, &tz) != 0)
5959
return 0;
6060

61-
return tv.tv_sec * 1000000 + tv.tv_usec;
61+
return static_cast<uint64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
6262
}
6363

6464
uint64_t GetCurrentMicrosecondsFrom1970() { return GetUtcMicroseconds(); }
6565

66-
bool GetUtc(uint32_t &sec, uint64_t &usec)
66+
bool GetUtc(uint32_t &sec, uint32_t &usec)
6767
{
6868
struct timeval tv;
6969
struct timezone tz;

modules/util/timestamp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ uint64_t GetUtcMicroseconds();
3939
uint64_t GetCurrentMicrosecondsFrom1970();
4040

4141
//! 获取当前的时间戳,秒 + 微秒
42-
bool GetUtc(uint32_t &sec, uint64_t &usec);
42+
bool GetUtc(uint32_t &sec, uint32_t &usec);
4343

4444
//! 获取指定时间戳的0时区时间字串
4545
std::string GetUtcTimeString(uint32_t utc_sec);

0 commit comments

Comments
 (0)