From 08f16a9dde12a5631ca3a24b888816465212963b Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 4 Feb 2022 19:42:42 +0100 Subject: [PATCH] Simplify switch to TCPIP function Do not use an output parameter to return the value. Instead, return the actual ip:port string on success or NULL on error. --- app/src/server.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/server.c b/app/src/server.c index abdaa6a4..2d4f70b8 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -580,8 +580,8 @@ append_port_5555(const char *ip) { return ip_port; } -static bool -sc_server_switch_to_tcpip(struct sc_server *server, char **out_ip_port) { +static char * +sc_server_switch_to_tcpip(struct sc_server *server) { const char *serial = server->params.serial; assert(serial); @@ -590,13 +590,13 @@ sc_server_switch_to_tcpip(struct sc_server *server, char **out_ip_port) { char *ip = sc_adb_get_device_ip(intr, serial, 0); if (!ip) { LOGE("Device IP not found"); - return false; + return NULL; } char *ip_port = append_port_5555(ip); free(ip); if (!ip_port) { - return false; + return NULL; } bool tcp_mode = is_tcpip_mode_enabled(server); @@ -616,13 +616,11 @@ sc_server_switch_to_tcpip(struct sc_server *server, char **out_ip_port) { } } - *out_ip_port = ip_port; - - return true; + return ip_port; error: free(ip_port); - return false; + return NULL; } static bool @@ -687,8 +685,8 @@ sc_server_configure_tcpip(struct sc_server *server) { return true; } - bool ok = sc_server_switch_to_tcpip(server, &ip_port); - if (!ok) { + ip_port = sc_server_switch_to_tcpip(server); + if (!ip_port) { return false; } }