今天我的代码突然失效了,有什么问题吗?这是代码的一部分。
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
int32_t tnow = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
if (tnow - decoder->last_dumped >= 300) {
decoder->last_dumped = tnow;
// it was working before
...
}发布于 2022-06-24 10:32:21
tv_sec是一个有符号整数,保持秒,所以1000 * tv_sec会使int32_t溢出。使用int64_t。
溢出将在(1 << 31)毫秒后发生,大约为24.8天。
https://stackoverflow.com/questions/72742471
复制相似问题