[FFmpeg-cvslog] os_support: Don't compare a negative number against socket descriptors

Martin Storsjö git at videolan.org
Sat Jun 30 22:47:42 CEST 2012


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Sun Jun 24 22:36:37 2012 +0300| [71078ad3338d850a24071e93b69d2109a943f73e] | committer: Martin Storsjö

os_support: Don't compare a negative number against socket descriptors

The fds are unsigned integers in the windows definition of struct
sockfds. Due to this, the comparison if (fds[i].fd > n) was always
false.

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=71078ad3338d850a24071e93b69d2109a943f73e
---

 libavformat/os_support.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavformat/os_support.c b/libavformat/os_support.c
index 8054ba6..49ec0c6 100644
--- a/libavformat/os_support.c
+++ b/libavformat/os_support.c
@@ -286,7 +286,7 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout)
     FD_ZERO(&write_set);
     FD_ZERO(&exception_set);
 
-    n = -1;
+    n = 0;
     for(i = 0; i < numfds; i++) {
         if (fds[i].fd < 0)
             continue;
@@ -301,22 +301,22 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout)
         if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &write_set);
         if (fds[i].events & POLLERR) FD_SET(fds[i].fd, &exception_set);
 
-        if (fds[i].fd > n)
-            n = fds[i].fd;
+        if (fds[i].fd >= n)
+            n = fds[i].fd + 1;
     };
 
-    if (n == -1)
+    if (n == 0)
         /* Hey!? Nothing to poll, in fact!!! */
         return 0;
 
     if (timeout < 0)
-        rc = select(n+1, &read_set, &write_set, &exception_set, NULL);
+        rc = select(n, &read_set, &write_set, &exception_set, NULL);
     else {
         struct timeval    tv;
 
         tv.tv_sec = timeout / 1000;
         tv.tv_usec = 1000 * (timeout % 1000);
-        rc = select(n+1, &read_set, &write_set, &exception_set, &tv);
+        rc = select(n, &read_set, &write_set, &exception_set, &tv);
     };
 
     if (rc < 0)



More information about the ffmpeg-cvslog mailing list