From: Martin Ling Date: Wed, 27 May 2015 10:21:56 +0000 (+0100) Subject: Fix possible use of uninitialised variable in poll() setup. X-Git-Tag: libserialport-0.1.1~22 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=6b8eee06823c3ba843c10ea2c6c19be517d34512;p=libserialport.git Fix possible use of uninitialised variable in poll() setup. --- diff --git a/serialport.c b/serialport.c index da292ac..7af818e 100644 --- a/serialport.c +++ b/serialport.c @@ -1457,7 +1457,11 @@ SP_API enum sp_return sp_wait(struct sp_event_set *event_set, * to avoid any issues if a short timeout is reached before * poll() is even run. */ - if (timeout_ms && started) { + if (!timeout_ms) { + timeout_remaining_ms = -1; + } else if (!started) { + timeout_remaining_ms = timeout_ms; + } else { gettimeofday(&now, NULL); if (timercmp(&now, &end, >)) { DEBUG("Wait timed out"); @@ -1467,7 +1471,7 @@ SP_API enum sp_return sp_wait(struct sp_event_set *event_set, timeout_remaining_ms = delta.tv_sec * 1000 + delta.tv_usec / 1000; } - result = poll(pollfds, event_set->count, timeout_ms ? timeout_remaining_ms : -1); + result = poll(pollfds, event_set->count, timeout_remaining_ms); started = 1; if (result < 0) {