apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Garrett Rooney <roo...@electricjellyfish.net>
Subject Re: cvs commit: apr/poll/unix poll.c
Date Fri, 03 Jan 2003 17:12:12 GMT
Brian Pane wrote:

>On Fri, 2003-01-03 at 08:05, Joe Orton wrote:
>  
>
>>On Tue, Dec 31, 2002 at 05:10:40PM -0000, William Rowe wrote:
>>    
>>
>>>  Modified:    poll/unix poll.c
>>>  Log:
>>>    Fix apr_poll behavior on Darwin/Win32 (now passing testpoll.)
>>>    We were getting spurious returned events because the select-based
>>>    poll implementation wasn't zeroing out previous results before
>>>    setting the current ones and returning.
>>>  
>>>  Submitted by:	Garrett Rooney <rooneg@electricjellyfish.net>
>>>  
>>>  Revision  Changes    Path
>>>  1.33      +4 -0      apr/poll/unix/poll.c
>>>  --- poll.c	20 Sep 2002 10:42:37 -0000	1.32
>>>  +++ poll.c	31 Dec 2002 17:10:40 -0000	1.33
>>>  @@ -275,6 +275,10 @@
>>>       }
>>>   #endif
>>>   
>>>  +    for (i = 0; i < *nsds; i++) {
>>>  +      aprset[i].rtnevents = 0;
>>>  +    }
>>>  +
>>>       (*nsds) = rv;
>>>      
>>>
>>I don't think this is correct; *nsds is a return value and isn't defined
>>until the following line, so this may cause i to overrun the array. (I'm
>>seeing memory corruption from this on some platforms)
>>    
>>
>
>Yeah, that looks bad.
>

good catch.  i should have noticed that.

>  
>
>>Even so, why is this change necessary, since the for loop at the end of
>>the function is doing exactly the same thing already?
>>    
>>
>
>If select returns zero (no descriptors signaled), the function
>will exit before it ever reaches that loop.  However, the
>"for (i = 0; i < *nsds; i++)" loop isn't right, either; even
>when *nsds is initialized, it's only equal to the number of
>descriptors that have been signaled, not the total number
>of descriptors in the input vector.  We need to loop to
>num instead of *nsds.
>  
>

yeah, that's the reason we need to clear it, and the way it should be done.

thanks,

-garrett


Mime
View raw message