fix timeout calc bug reported by philip (thanks!)
This was SVN commit r2047.
This commit is contained in:
parent
c2b7df72ce
commit
481cd97d92
@ -287,12 +287,17 @@ static DWORD calc_timeout_length_ms(const struct timespec* abs_timeout,
|
|||||||
|
|
||||||
timeout_is_valid = true;
|
timeout_is_valid = true;
|
||||||
|
|
||||||
i64 ds = abs_timeout->tv_sec - cur_time.tv_sec; // i64 to avoid overflow
|
// convert absolute deadline to relative length
|
||||||
long dn = abs_timeout->tv_nsec - cur_time.tv_nsec;
|
// note: use i64 to avoid overflow in multiply
|
||||||
|
const i64 ds = abs_timeout->tv_sec - cur_time.tv_sec;
|
||||||
|
const long dn = abs_timeout->tv_nsec - cur_time.tv_nsec;
|
||||||
i64 length_ms = ds*1000 + dn/1000000;
|
i64 length_ms = ds*1000 + dn/1000000;
|
||||||
// > 49 days -> result doesn't fit in 32 bits; most likely bogus.
|
// .. deadline already reached; we'll still attempt to lock once
|
||||||
// also be careful to avoid returning exactly -1,
|
if(length_ms < 0)
|
||||||
// because that's the Win32 INFINITE value.
|
return 0;
|
||||||
|
// .. length > 49 days => result won't fit in 32 bits. most likely bogus.
|
||||||
|
// note: we're careful to avoid returning exactly -1 since
|
||||||
|
// that's the Win32 INFINITE value.
|
||||||
if(length_ms >= 0xffffffff)
|
if(length_ms >= 0xffffffff)
|
||||||
{
|
{
|
||||||
debug_warn("calc_timeout_length_ms: 32-bit overflow");
|
debug_warn("calc_timeout_length_ms: 32-bit overflow");
|
||||||
|
Loading…
Reference in New Issue
Block a user