Index: glib/gmain.c
===================================================================
--- glib/gmain.c	(revision 6870)
+++ glib/gmain.c	(working copy)
@@ -2385,43 +2385,40 @@
 {
   gint n_poll;
   GPollRec *pollrec;
-  
+
   LOCK_CONTEXT (context);
 
   pollrec = context->poll_records;
   n_poll = 0;
   while (pollrec && max_priority >= pollrec->priority)
     {
-      if (pollrec->fd->events)
-	{
-	  if (n_poll < n_fds)
-	    {
-	      fds[n_poll].fd = pollrec->fd->fd;
-	      /* In direct contradiction to the Unix98 spec, IRIX runs into
-	       * difficulty if you pass in POLLERR, POLLHUP or POLLNVAL
-	       * flags in the events field of the pollfd while it should
-	       * just ignoring them. So we mask them out here.
-	       */
-	      fds[n_poll].events = pollrec->fd->events & ~(G_IO_ERR|G_IO_HUP|G_IO_NVAL);
-	      fds[n_poll].revents = 0;
-	    }
-	  n_poll++;
-	}
-      
+      if (pollrec->fd->events && n_poll < n_fds)
+	{
+	  fds[n_poll].fd = pollrec->fd->fd;
+	  /* In direct contradiction to the Unix98 spec, IRIX runs into
+	   * difficulty if you pass in POLLERR, POLLHUP or POLLNVAL
+	   * flags in the events field of the pollfd while it should
+	   * just ignoring them. So we mask them out here.
+	   */
+	  fds[n_poll].events = pollrec->fd->events & ~(G_IO_ERR|G_IO_HUP|G_IO_NVAL);
+	  fds[n_poll].revents = 0;
+	}
+
       pollrec = pollrec->next;
+      n_poll++;
     }
 
 #ifdef G_THREADS_ENABLED
   context->poll_changed = FALSE;
 #endif
-  
+
   if (timeout)
     {
       *timeout = context->timeout;
       if (*timeout != 0)
 	context->time_is_current = FALSE;
     }
-  
+
   UNLOCK_CONTEXT (context);
 
   return n_poll;
@@ -2480,17 +2477,16 @@
       return FALSE;
     }
 #endif /* G_THREADS_ENABLED */
-  
+
   pollrec = context->poll_records;
   i = 0;
   while (i < n_fds)
     {
       if (pollrec->fd->events)
-	{
-	  pollrec->fd->revents = fds[i].revents;
-	  i++;
-	}
+	pollrec->fd->revents = fds[i].revents;
+
       pollrec = pollrec->next;
+      i++;
     }
 
   source = next_valid_source (context, NULL);
@@ -2970,31 +2966,29 @@
       i = 0;
       while (i < n_fds)
 	{
-	  if (pollrec->fd->events)
-	    {
-	      if (fds[i].revents)
-		{
-		  g_print (" [%d:", fds[i].fd);
-		  if (fds[i].revents & G_IO_IN)
-		    g_print ("i");
-		  if (fds[i].revents & G_IO_OUT)
-		    g_print ("o");
-		  if (fds[i].revents & G_IO_PRI)
-		    g_print ("p");
-		  if (fds[i].revents & G_IO_ERR)
-		    g_print ("e");
-		  if (fds[i].revents & G_IO_HUP)
-		    g_print ("h");
-		  if (fds[i].revents & G_IO_NVAL)
-		    g_print ("n");
-		  g_print ("]");
-		}
-	      i++;
-	    }
+	  if (pollrec->fd->events && fds[i].revents)
+	    {
+	      g_print (" [%d:", fds[i].fd);
+	      if (fds[i].revents & G_IO_IN)
+		g_print ("i");
+	      if (fds[i].revents & G_IO_OUT)
+		g_print ("o");
+	      if (fds[i].revents & G_IO_PRI)
+		g_print ("p");
+	      if (fds[i].revents & G_IO_ERR)
+		g_print ("e");
+	      if (fds[i].revents & G_IO_HUP)
+		g_print ("h");
+	      if (fds[i].revents & G_IO_NVAL)
+		g_print ("n");
+	      g_print ("]");
+	    }
+
 	  pollrec = pollrec->next;
+	  i++;
 	}
       g_print ("\n");
-      
+
       UNLOCK_CONTEXT (context);
 #endif
     } /* if (n_fds || timeout != 0) */
