From: Larry D'Anna Date: Wed, 17 Feb 2010 00:04:56 GMT Subject: Re: [PATCH v3 2/4] Refactoring: connect.c: move duplicated code to a new function 'get_host_and_port' Message-ID: <20100217000456.GA28433@cthulhu> In-Reply-To: <0d6d0066fecc892bd5b6afda64e1aa5591347504.1266360267.git.michael.lukashov@gmail.com> * Michael Lukashov (michael.lukashov@gmail.com) [100216 18:43]: > @@ -170,30 +192,14 @@ static const char *ai_name(const struct addrinfo *ai) > static int git_tcp_connect_sock(char *host, int flags) > { > int sockfd = -1, saved_errno = 0; > - char *colon, *end; > const char *port = STR(DEFAULT_GIT_PORT); > struct addrinfo hints, *ai0, *ai; > int gai; > int cnt = 0; > > - if (host[0] == '[') { > - end = strchr(host + 1, ']'); > - if (end) { > - *end = 0; > - end++; > - host++; > - } else > - end = host; > - } else > - end = host; > - colon = strchr(end, ':'); > - > - if (colon) { > - *colon = 0; > - port = colon + 1; > - if (!*port) > - port = ""; > - } > + get_host_and_port(&host, &port); > + if (!*port) > + *port = ""; Again, isn't this wrong? This doesn't even compile for me. Shouldn't it be port = ""; ?? What am I missing? --larry