fixing off-by-one
authorChristian Grothoff <christian@grothoff.org>
Wed, 20 Oct 2010 08:01:20 +0000 (08:01 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 20 Oct 2010 08:01:20 +0000 (08:01 +0000)
src/util/network.c

index cf74d43add439142e5ec259e10918aef285a786c..a1142d43341b80c0b99d7ef69494529a4431ede4 100644 (file)
@@ -900,12 +900,16 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
                               const struct GNUNET_NETWORK_FDSet *fds2)
 {
   int nfds;
+
   nfds = fds1->nsds;
-  if (nfds < fds2->nsds)
+  if (nfds > fds2->nsds)
     nfds = fds2->nsds;
-  for (; nfds >= 0; nfds--)
-    if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds))
-      return GNUNET_YES;
+  while (nfds > 0)
+    {
+      nfds--;
+      if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds))
+       return GNUNET_YES;
+    }
 #ifdef MINGW
   {
     struct GNUNET_CONTAINER_SList_Iterator *it;