svn commit: r183989 - head/lib/libutil

Xin LI delphij at FreeBSD.org
Fri Oct 17 21:21:15 UTC 2008


Author: delphij
Date: Fri Oct 17 21:21:14 2008
New Revision: 183989
URL: http://svn.freebsd.org/changeset/base/183989

Log:
  Use strlcpy() when we mean it.

Modified:
  head/lib/libutil/login_times.c
  head/lib/libutil/logwtmp.c
  head/lib/libutil/realhostname.c

Modified: head/lib/libutil/login_times.c
==============================================================================
--- head/lib/libutil/login_times.c	Fri Oct 17 21:14:50 2008	(r183988)
+++ head/lib/libutil/login_times.c	Fri Oct 17 21:21:14 2008	(r183989)
@@ -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]);
 

Modified: head/lib/libutil/logwtmp.c
==============================================================================
--- head/lib/libutil/logwtmp.c	Fri Oct 17 21:14:50 2008	(r183988)
+++ head/lib/libutil/logwtmp.c	Fri Oct 17 21:21:14 2008	(r183989)
@@ -59,8 +59,7 @@ logwtmp(const char *line, const char *na
 	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;
 

Modified: head/lib/libutil/realhostname.c
==============================================================================
--- head/lib/libutil/realhostname.c	Fri Oct 17 21:14:50 2008	(r183988)
+++ head/lib/libutil/realhostname.c	Fri Oct 17 21:21:14 2008	(r183989)
@@ -61,8 +61,7 @@ realhostname(char *host, size_t hsize, c
 		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;


More information about the svn-src-head mailing list