]> sigrok.org Git - libserialport.git/commitdiff
Fix possible use of uninitialised variable in poll() setup.
authorMartin Ling <redacted>
Wed, 27 May 2015 10:21:56 +0000 (11:21 +0100)
committerUwe Hermann <redacted>
Sat, 30 May 2015 19:38:03 +0000 (21:38 +0200)
serialport.c

index da292ac650ffff5e1099733fe58271cf16b60248..7af818e2d2574ca022b5a0cce57b55da8ffcabaf 100644 (file)
@@ -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) {