RangeNetworks / OpenBTS-UMTS

3G UMTS Data Radio Access Network Node
GNU Affero General Public License v3.0
300 stars 195 forks source link

CommonLibs/Timeval.cpp:61 delta() problem #49

Open wangzhanwei666 opened 2 years ago

wangzhanwei666 commented 2 years ago

Original: long Timeval::delta(const Timeval& other) const { // 2^31 milliseconds is just over 4 years. long deltaS = other.sec() - sec(); long deltaUs = other.usec() - usec(); return 1000*deltaS + deltaUs/1000; }

should Be: long Timeval::delta(const Timeval& other) const { // 2^31 milliseconds is just over 4 years. long deltaS = (long)other.sec() - (long)sec(); long deltaUs = (long)other.usec() - (long)usec(); return 1000*deltaS + deltaUs/1000; }

Reason: usec() return uint32_t type, which will result in (1-2) > 0, deltaUs will be wrong!!!