diff --git a/src/main/main.c b/src/main/main.c index 824d92535..a70e9740a 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -287,33 +287,35 @@ static void fd_handler(struct re_fhs *fhs, int flags) #ifdef HAVE_SELECT static int set_select_fds(struct re *re, struct re_fhs *fhs) { - int i; + int i = -1; if (!re || !fhs) return EINVAL; if (fhs->index != -1) { i = fhs->index; - goto update; } - - /* if nothing is found a linear search for the first - * zeroed handler */ - for (i = 0; i < re->maxfds; i++) { - if (!re->fhsl[i]) - goto update; + else { + /* if nothing is found a linear search for the first + * zeroed handler */ + for (int j = 0; j < re->maxfds; j++) { + if (!re->fhsl[j]) { + i = j; + break; + } + } } - return ERANGE; + if (i == -1) + return ERANGE; -update: if (fhs->flags) { re->fhsl[i] = fhs; - fhs->index = i; + fhs->index = i; } else { re->fhsl[i] = NULL; - fhs->index = -1; + fhs->index = -1; } return 0;