Fix a fencepost bug in the select backend
authorNick Mathewson <nickm@torproject.org>
Mon, 30 May 2011 15:53:19 +0000 (11:53 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 30 May 2011 15:53:19 +0000 (11:53 -0400)
This bug would sometimes lead us to looking one bit off the end of
the fdset arrays, and trying to activate a (nonexistent) event if
that bit was set.

Found by Harlann Stenn.  Fixes a test failure on OpenSolaris.

select.c

index 9495631813a03a5593a19ced55cace2a028f4c7c..892ddfaf222aa0541bdc77a02364559e523f1d4c 100644 (file)
--- a/select.c
+++ b/select.c
@@ -172,9 +172,9 @@ select_dispatch(struct event_base *base, struct timeval *tv)
        event_debug(("%s: select reports %d", __func__, res));
 
        check_selectop(sop);
-       i = random() % (nfds+1);
-       for (j = 0; j <= nfds; ++j) {
-               if (++i >= nfds+1)
+       i = random() % nfds;
+       for (j = 0; j < nfds; ++j) {
+               if (++i >= nfds)
                        i = 0;
                res = 0;
                if (FD_ISSET(i, sop->event_readset_out))