From cf2c7d48380969200034afeab93169e68c34c397 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Wed, 23 Dec 2020 17:39:01 -0800 Subject: [clang-tidy] Do not use else after return Signed-off-by: Rosen Penev --- src/idevice.c | 76 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 37 deletions(-) (limited to 'src/idevice.c') diff --git a/src/idevice.c b/src/idevice.c index f64570b..adf47f4 100644 --- a/src/idevice.c +++ b/src/idevice.c @@ -473,7 +473,8 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connect(idevice_t device, uint16_t new_connection->status = IDEVICE_E_SUCCESS; *connection = new_connection; return IDEVICE_E_SUCCESS; - } else if (device->conn_type == CONNECTION_NETWORK) { + } + if (device->conn_type == CONNECTION_NETWORK) { struct sockaddr_storage saddr_storage; struct sockaddr* saddr = (struct sockaddr*)&saddr_storage; @@ -529,10 +530,9 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connect(idevice_t device, uint16_t *connection = new_connection; return IDEVICE_E_SUCCESS; - } else { - debug_info("Unknown connection type %d", device->conn_type); } + debug_info("Unknown connection type %d", device->conn_type); return IDEVICE_E_UNKNOWN_ERROR; } @@ -583,7 +583,8 @@ static idevice_error_t internal_connection_send(idevice_connection_t connection, return IDEVICE_E_UNKNOWN_ERROR; } return IDEVICE_E_SUCCESS; - } else if (connection->type == CONNECTION_NETWORK) { + } + if (connection->type == CONNECTION_NETWORK) { int s = socket_send((int)(long)connection->data, (void*)data, len); if (s < 0) { *sent_bytes = 0; @@ -591,9 +592,9 @@ static idevice_error_t internal_connection_send(idevice_connection_t connection, } *sent_bytes = s; return IDEVICE_E_SUCCESS; - } else { - debug_info("Unknown connection type %d", connection->type); } + + debug_info("Unknown connection type %d", connection->type); return IDEVICE_E_UNKNOWN_ERROR; } @@ -638,27 +639,26 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_send(idevice_connection_ } *sent_bytes = sent; return IDEVICE_E_SUCCESS; - } else { - uint32_t sent = 0; - while (sent < len) { - uint32_t bytes = 0; - int s = internal_connection_send(connection, data+sent, len-sent, &bytes); - if (s < 0) { - break; - } - sent += bytes; - } - debug_info("len %d, sent %d", len, sent); - if (sent < len) { - *sent_bytes = sent; - if (sent == 0) { - return IDEVICE_E_UNKNOWN_ERROR; - } - return IDEVICE_E_NOT_ENOUGH_DATA; + } + uint32_t sent = 0; + while (sent < len) { + uint32_t bytes = 0; + int s = internal_connection_send(connection, data+sent, len-sent, &bytes); + if (s < 0) { + break; } + sent += bytes; + } + debug_info("internal_connection_send %d, sent %d", len, sent); + if (sent < len) { *sent_bytes = sent; - return IDEVICE_E_SUCCESS; + if (sent == 0) { + return IDEVICE_E_UNKNOWN_ERROR; + } + return IDEVICE_E_NOT_ENOUGH_DATA; } + *sent_bytes = sent; + return IDEVICE_E_SUCCESS; } static inline idevice_error_t socket_recv_to_idevice_error(int conn_error, uint32_t len, uint32_t received) @@ -698,7 +698,8 @@ static idevice_error_t internal_connection_receive_timeout(idevice_connection_t debug_info("ERROR: usbmuxd_recv_timeout returned %d (%s)", conn_error, strerror(-conn_error)); } return error; - } else if (connection->type == CONNECTION_NETWORK) { + } + if (connection->type == CONNECTION_NETWORK) { int res = socket_receive_timeout((int)(long)connection->data, data, len, 0, timeout); idevice_error_t error = socket_recv_to_idevice_error(res, 0, 0); if (error == IDEVICE_E_SUCCESS) { @@ -707,9 +708,9 @@ static idevice_error_t internal_connection_receive_timeout(idevice_connection_t debug_info("ERROR: socket_receive_timeout returned %d (%s)", res, strerror(-res)); } return error; - } else { - debug_info("Unknown connection type %d", connection->type); } + + debug_info("Unknown connection type %d", connection->type); return IDEVICE_E_UNKNOWN_ERROR; } @@ -793,7 +794,8 @@ static idevice_error_t internal_connection_receive(idevice_connection_t connecti return IDEVICE_E_UNKNOWN_ERROR; } return IDEVICE_E_SUCCESS; - } else if (connection->type == CONNECTION_NETWORK) { + } + if (connection->type == CONNECTION_NETWORK) { int res = socket_receive((int)(long)connection->data, data, len); if (res < 0) { debug_info("ERROR: socket_receive returned %d (%s)", res, strerror(-res)); @@ -801,9 +803,9 @@ static idevice_error_t internal_connection_receive(idevice_connection_t connecti } *recv_bytes = (uint32_t)res; return IDEVICE_E_SUCCESS; - } else { - debug_info("Unknown connection type %d", connection->type); } + + debug_info("Unknown connection type %d", connection->type); return IDEVICE_E_UNKNOWN_ERROR; } @@ -846,17 +848,17 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_get_fd(idevice_connectio return IDEVICE_E_INVALID_ARG; } - idevice_error_t result = IDEVICE_E_UNKNOWN_ERROR; if (connection->type == CONNECTION_USBMUXD) { *fd = (int)(long)connection->data; - result = IDEVICE_E_SUCCESS; - } else if (connection->type == CONNECTION_NETWORK) { + return IDEVICE_E_SUCCESS; + } + if (connection->type == CONNECTION_NETWORK) { *fd = (int)(long)connection->data; - result = IDEVICE_E_SUCCESS; - } else { - debug_info("Unknown connection type %d", connection->type); + return IDEVICE_E_SUCCESS; } - return result; + + debug_info("Unknown connection type %d", connection->type); + return IDEVICE_E_UNKNOWN_ERROR; } LIBIMOBILEDEVICE_API idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle) -- cgit v1.1-32-gdbae