From e5dd9952d78e6b9a7a6e18cb4da8dd71352a1ba1 Mon Sep 17 00:00:00 2001 From: wh201906 Date: Wed, 27 Dec 2023 22:13:26 +0800 Subject: [PATCH] Misc Change style of if block with single statement Reset rx_empty_counter in uart_open() --- client/src/uart/uart_posix.c | 13 +++++++++---- client/src/uart/uart_win32.c | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/client/src/uart/uart_posix.c b/client/src/uart/uart_posix.c index c29c72826..325d26abd 100644 --- a/client/src/uart/uart_posix.c +++ b/client/src/uart/uart_posix.c @@ -90,6 +90,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { } sp->udpBuffer = NULL; + rx_empty_counter = 0; // init timeouts timeout.tv_usec = UART_FPC_CLIENT_RX_TIMEOUT_MS * 1000; g_conn.send_via_local_ip = false; @@ -157,10 +158,12 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { } // for bind option, it's possible to only specify address or port - if (strlen(bindAddrStr) == 0) + if (strlen(bindAddrStr) == 0) { bindAddrStr = NULL; - if (bindPortStr != NULL && strlen(bindPortStr) == 0) + } + if (bindPortStr != NULL && strlen(bindPortStr) == 0) { bindPortStr = NULL; + } } const char *addrStr = NULL; @@ -208,8 +211,9 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { for (rp = addr; rp != NULL; rp = rp->ai_next) { sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - if (sfd == -1) + if (sfd == -1) { continue; + } if (!uart_bind(&sfd, bindAddrStr, bindPortStr, isBindingIPv6)) { PrintAndLogEx(ERR, "error: Could not bind. errno: %d", errno); @@ -220,8 +224,9 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { return INVALID_SERIAL_PORT; } - if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) + if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) { break; + } close(sfd); } diff --git a/client/src/uart/uart_win32.c b/client/src/uart/uart_win32.c index 97ecd41bd..a343936d2 100644 --- a/client/src/uart/uart_win32.c +++ b/client/src/uart/uart_win32.c @@ -93,6 +93,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { } sp->udpBuffer = NULL; + rx_empty_counter = 0; g_conn.send_via_local_ip = false; g_conn.send_via_ip = PM3_NONE; @@ -149,10 +150,12 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { } // for bind option, it's possible to only specify address or port - if (strlen(bindAddrStr) == 0) + if (strlen(bindAddrStr) == 0) { bindAddrStr = NULL; - if (bindPortStr != NULL && strlen(bindPortStr) == 0) + } + if (bindPortStr != NULL && strlen(bindPortStr) == 0) { bindPortStr = NULL; + } } const char *addrStr = NULL; @@ -211,8 +214,9 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { for (rp = addr; rp != NULL; rp = rp->ai_next) { hSocket = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - if (hSocket == INVALID_SOCKET) + if (hSocket == INVALID_SOCKET) { continue; + } if (!uart_bind(&hSocket, bindAddrStr, bindPortStr, isBindingIPv6)) { PrintAndLogEx(ERR, "error: Could not bind. error: %u", WSAGetLastError()); @@ -225,8 +229,9 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { return INVALID_SERIAL_PORT; } - if (connect(hSocket, rp->ai_addr, (int)rp->ai_addrlen) != INVALID_SOCKET) + if (connect(hSocket, rp->ai_addr, (int)rp->ai_addrlen) != INVALID_SOCKET) { break; + } closesocket(hSocket); hSocket = INVALID_SOCKET;