Use strlcpy() instead of strncpy() when we want the string to be

NUL-terminated.
This commit is contained in:
Xin LI 2008-10-13 22:50:38 +00:00
parent e4866772c3
commit 3a4e1f4703

View File

@ -233,11 +233,10 @@ setpeer0(host, port)
/* res->ai_addr <= sizeof(peeraddr) is guaranteed */
memcpy(&peeraddr, res->ai_addr, res->ai_addrlen);
if (res->ai_canonname) {
(void) strncpy(hostname, res->ai_canonname,
(void) strlcpy(hostname, res->ai_canonname,
sizeof(hostname));
} else
(void) strncpy(hostname, host, sizeof(hostname));
hostname[sizeof(hostname)-1] = 0;
(void) strlcpy(hostname, host, sizeof(hostname));
connected = 1;
}