Use strlcpy() when we mean it.

This commit is contained in:
Xin LI 2008-10-17 21:21:14 +00:00
parent 1c10962832
commit 0ea291e221
3 changed files with 3 additions and 6 deletions

View File

@ -72,8 +72,7 @@ parse_lt(const char * str)
char buf[64];
/* Make local copy and force lowercase to simplify parsing */
p = strncpy(buf, str, sizeof buf);
buf[sizeof buf - 1] = '\0';
p = strlcpy(buf, str, sizeof buf);
for (i = 0; buf[i]; i++)
buf[i] = (char)tolower(buf[i]);

View File

@ -59,8 +59,7 @@ logwtmp(const char *line, const char *name, const char *host)
char fullhost[MAXHOSTNAMELEN];
int fd;
strncpy(fullhost, host, sizeof(fullhost) - 1);
fullhost[sizeof(fullhost) - 1] = '\0';
strlcpy(fullhost, host, sizeof(fullhost));
trimdomain(fullhost, UT_HOSTSIZE);
host = fullhost;

View File

@ -61,8 +61,7 @@ realhostname(char *host, size_t hsize, const struct in_addr *ip)
if (strlen(trimmed) <= hsize) {
char lookup[MAXHOSTNAMELEN];
strncpy(lookup, hp->h_name, sizeof(lookup) - 1);
lookup[sizeof(lookup) - 1] = '\0';
strlcpy(lookup, hp->h_name, sizeof(lookup));
hp = gethostbyname(lookup);
if (hp == NULL)
result = HOSTNAME_INVALIDNAME;