Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wangzhanwei666 opened this issue Jun 1, 2022 · 0 comments
Open

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

wangzhanwei666 opened this issue Jun 1, 2022 · 0 comments

Comments

@wangzhanwei666
Copy link

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!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant