From e7168f30e6fdf0a1f9cffdc9252f52d45e5a59ef Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Wed, 3 Jun 2020 15:46:25 -0700 Subject: Do not use else after return or break for better code readability [clang-tidy] Found with readability-else-after-return Signed-off-by: Rosen Penev --- tools/inetcat.c | 3 ++- tools/iproxy.c | 40 ++++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 21 deletions(-) (limited to 'tools') diff --git a/tools/inetcat.c b/tools/inetcat.c index 1674c81..59c18b2 100644 --- a/tools/inetcat.c +++ b/tools/inetcat.c @@ -197,7 +197,8 @@ int main(int argc, char **argv) if (dev_list[i].conn_type == CONNECTION_TYPE_USB && (lookup_opts & DEVICE_LOOKUP_USBMUX)) { dev = &(dev_list[i]); break; - } else if (dev_list[i].conn_type == CONNECTION_TYPE_NETWORK && (lookup_opts & DEVICE_LOOKUP_NETWORK)) { + } + if (dev_list[i].conn_type == CONNECTION_TYPE_NETWORK && (lookup_opts & DEVICE_LOOKUP_NETWORK)) { dev = &(dev_list[i]); break; } diff --git a/tools/iproxy.c b/tools/iproxy.c index 28fcb46..5dca580 100644 --- a/tools/iproxy.c +++ b/tools/iproxy.c @@ -112,7 +112,8 @@ static void *acceptor_thread(void *arg) if (dev_list[i].conn_type == CONNECTION_TYPE_USB && (cdata->lookup_opts & DEVICE_LOOKUP_USBMUX)) { dev = &(dev_list[i]); break; - } else if (dev_list[i].conn_type == CONNECTION_TYPE_NETWORK && (cdata->lookup_opts & DEVICE_LOOKUP_NETWORK)) { + } + if (dev_list[i].conn_type == CONNECTION_TYPE_NETWORK && (cdata->lookup_opts & DEVICE_LOOKUP_NETWORK)) { dev = &(dev_list[i]); break; } @@ -459,28 +460,27 @@ int main(int argc, char **argv) if (c_sock < 0) { fprintf(stderr, "accept: %s\n", strerror(errno)); break; - } else { - printf("New connection for %d->%d, fd = %d\n", listen_port[listen_sock[i].index], device_port[listen_sock[i].index], c_sock); - cdata = (struct client_data*)malloc(sizeof(struct client_data)); - if (!cdata) { - socket_close(c_sock); - fprintf(stderr, "ERROR: Out of memory\n"); - free(device_udid); - return -1; - } - cdata->fd = c_sock; - cdata->sfd = -1; - cdata->udid = (device_udid) ? strdup(device_udid) : NULL; - cdata->lookup_opts = lookup_opts; - cdata->device_port = device_port[listen_sock[i].index]; + } + printf("New connection for %d->%d, fd = %d\n", listen_port[listen_sock[i].index], device_port[listen_sock[i].index], c_sock); + cdata = (struct client_data*)malloc(sizeof(struct client_data)); + if (!cdata) { + socket_close(c_sock); + fprintf(stderr, "ERROR: Out of memory\n"); + free(device_udid); + return -1; + } + cdata->fd = c_sock; + cdata->sfd = -1; + cdata->udid = (device_udid) ? strdup(device_udid) : NULL; + cdata->lookup_opts = lookup_opts; + cdata->device_port = device_port[listen_sock[i].index]; #ifdef WIN32 - acceptor = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)acceptor_thread, cdata, 0, NULL); - CloseHandle(acceptor); + acceptor = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)acceptor_thread, cdata, 0, NULL); + CloseHandle(acceptor); #else - pthread_create(&acceptor, NULL, acceptor_thread, cdata); - pthread_detach(acceptor); + pthread_create(&acceptor, NULL, acceptor_thread, cdata); + pthread_detach(acceptor); #endif - } } } } -- cgit v1.1-32-gdbae