1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

multi: clarify condition in curl_multi_wait

`if(nfds || extra_nfds) {` is followed by `malloc(nfds * ...)`.

If `extra_fs` could be non-zero when `nfds` was zero, then we have
`malloc(0)` which is allowed to return `NULL`. But, malloc returning
NULL can be confusing. In this code, the next line would treat the NULL
as an allocation failure.

It turns out, if `nfds` is zero then `extra_nfds` must also be zero.
The final value of `nfds` includes `extra_nfds`.  So the test for
`extra_nfds` is redundant.  It can only confuse the reader.

Closes #1439
This commit is contained in:
Alan Jenkins 2017-04-22 21:16:44 +01:00 committed by Daniel Stenberg
parent 4a8cf6c404
commit be299a4dba

View File

@ -1014,7 +1014,7 @@ CURLMcode curl_multi_wait(struct Curl_multi *multi,
curlfds = nfds; /* number of internal file descriptors */ curlfds = nfds; /* number of internal file descriptors */
nfds += extra_nfds; /* add the externally provided ones */ nfds += extra_nfds; /* add the externally provided ones */
if(nfds || extra_nfds) { if(nfds) {
if(nfds > NUM_POLLS_ON_STACK) { if(nfds > NUM_POLLS_ON_STACK) {
ufds = malloc(nfds * sizeof(struct pollfd)); ufds = malloc(nfds * sizeof(struct pollfd));
if(!ufds) if(!ufds)