Skip to content

sem_lock_wait存在时间运算溢出问题 #108

Open

Description

@xkf321

clock_gettime(CLOCK_REALTIME, &ts);
uint64_t ns = ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
ns += ms * 1000 * 1000;
ts.tv_sec = ns / (1000 * 1000 * 1000);
ts.tv_nsec = ns % 1000 * 1000 * 1000;
ret = sem_timedwait(lock, &ts);

uint64_t ns = ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
运行平台为arm32,计算ns 时会使用uint32类型,导致运算出现溢出, ts.tv_sec前增加强制转换为 uint64_t 可以解决

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions