Skip to content

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

Description

@wangzhanwei666

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions