]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
* event-loop.c (gdb_select): Program defensively.
authorMark Mitchell <mark@codesourcery.com>
Mon, 25 Apr 2005 23:51:33 +0000 (23:51 +0000)
committerMark Mitchell <mark@codesourcery.com>
Mon, 25 Apr 2005 23:51:33 +0000 (23:51 +0000)
gdb/ChangeLog
gdb/event-loop.c

index c4a9b6d24d1cde3fd1d2d2a4542062c82e78c2be..34cbd8c4534d4ebfc89f2ad8ec53c31e156d143a 100644 (file)
@@ -1,5 +1,7 @@
 2005-04-25  Mark Mitchell  <mark@codesourcery.com>
 
+       * event-loop.c (gdb_select): Program defensively.
+
        * event-loop.c (gdb_assert.h): Include.
        (<windows.h>): Include under Windows.
        (<io.h>): Likeiwse.
index 1db32a826ec8208306ef82b429ba7ab69aeca0b0..2f3d5359b79baa94fc2e30b3f11c9e1aea6b0f52 100644 (file)
@@ -760,7 +760,10 @@ gdb_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
         if something starts using it.  */
       gdb_assert (!FD_ISSET (fd, writefds));
       if (FD_ISSET (fd, readfds))
-       handles[num_handles++] = (HANDLE) _get_osfhandle (fd);
+       {
+         gdb_assert (num_handles < MAXIMUM_WAIT_OBJECTS);
+         handles[num_handles++] = (HANDLE) _get_osfhandle (fd);
+       }
     }
   event = WaitForMultipleObjects (num_handles,
                                  handles,
@@ -779,15 +782,17 @@ gdb_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
     return 0;
   /* Run through the READFDS, clearing bits corresponding to descriptors
      for which input is unavailable.  */
-  num_ready = num_handlers; 
+  num_ready = num_handles; 
   h = handles[event - WAIT_OBJECT_0];
   for (fd = 0; fd < n; ++fd)
     {
-      HANDLE fd_h = (HANDLE) _get_osfhandle (fd);
+      HANDLE fd_h;
+      if (!FD_ISSET (fd, readfds))
+       continue;
+      fd_h = (HANDLE) _get_osfhandle (fd);
       /* This handle might be ready, even though it wasn't the handle
         returned by WaitForMultipleObjects.  */
-      if (FD_ISSET (fd, readfds) && fd_h != h
-         && WaitForSingleObject (fd_h, 0) != WAIT_OBJECT_0)
+      if (fd_h != h && WaitForSingleObject (fd_h, 0) != WAIT_OBJECT_0)
        {
          FD_CLR (fd, readfds);
          --num_ready;