mirror of
https://github.com/neovim/neovim.git
synced 2025-10-01 23:48:32 +00:00
os/server: Fix TCP connection
- remove unused errno - remove unused port_end - correct calculation of addr_len - use correct string length during IP copy
This commit is contained in:

committed by
Nicolas Hillegeer

parent
7c473dc0a2
commit
fa5615022c
@@ -116,21 +116,19 @@ void server_start(char *endpoint)
|
|||||||
|
|
||||||
if (addr_len > sizeof(ip) - 1) {
|
if (addr_len > sizeof(ip) - 1) {
|
||||||
// Maximum length of an IP address buffer is 15(eg: 255.255.255.255)
|
// Maximum length of an IP address buffer is 15(eg: 255.255.255.255)
|
||||||
addr_len = sizeof(ip);
|
addr_len = sizeof(ip) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the address part
|
// Extract the address part
|
||||||
xstrlcpy(ip, addr, addr_len);
|
xstrlcpy(ip, addr, addr_len + 1);
|
||||||
|
|
||||||
int port = NEOVIM_DEFAULT_TCP_PORT;
|
int port = NEOVIM_DEFAULT_TCP_PORT;
|
||||||
|
|
||||||
if (*ip_end == ':') {
|
if (*ip_end == ':') {
|
||||||
char *port_end;
|
|
||||||
// Extract the port
|
// Extract the port
|
||||||
port = strtol(ip_end + 1, &port_end, 10);
|
port = strtol(ip_end + 1, NULL, 10);
|
||||||
errno = 0;
|
|
||||||
|
|
||||||
if (errno != 0 || port == 0 || port > 0xffff) {
|
if (port == 0 || port > 0xffff) {
|
||||||
// Invalid port, treat as named pipe or unix socket
|
// Invalid port, treat as named pipe or unix socket
|
||||||
server_type = kServerTypePipe;
|
server_type = kServerTypePipe;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user