aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2005-04-25 23:51:33 +0000
committerMark Mitchell <mark@codesourcery.com>2005-04-25 23:51:33 +0000
commit3aa6b2ca26ffaeeb2e3fb7a7c725829df8ad3601 (patch)
tree00d5720f481a96db4dac72d6dc14723a790a5ca4
parente459dc7b30e97b545ba146016bf15769b798b3d5 (diff)
downloadfsf-binutils-gdb-3aa6b2ca26ffaeeb2e3fb7a7c725829df8ad3601.zip
fsf-binutils-gdb-3aa6b2ca26ffaeeb2e3fb7a7c725829df8ad3601.tar.gz
fsf-binutils-gdb-3aa6b2ca26ffaeeb2e3fb7a7c725829df8ad3601.tar.bz2
* event-loop.c (gdb_select): Program defensively.
-rw-r--r--gdb/ChangeLog2
-rw-r--r--gdb/event-loop.c15
2 files changed, 12 insertions, 5 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c4a9b6d..34cbd8c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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.
diff --git a/gdb/event-loop.c b/gdb/event-loop.c
index 1db32a8..2f3d535 100644
--- a/gdb/event-loop.c
+++ b/gdb/event-loop.c
@@ -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;