Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Jul 2011 05:31:53 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r223922 - head/usr.bin/rpcgen
Message-ID:  <201107110531.p6B5Vrfn077306@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Mon Jul 11 05:31:52 2011
New Revision: 223922
URL: http://svn.freebsd.org/changeset/base/223922

Log:
  Use strlcpy().
  
  MFC after:	1 month

Modified:
  head/usr.bin/rpcgen/rpc_scan.c

Modified: head/usr.bin/rpcgen/rpc_scan.c
==============================================================================
--- head/usr.bin/rpcgen/rpc_scan.c	Mon Jul 11 05:22:31 2011	(r223921)
+++ head/usr.bin/rpcgen/rpc_scan.c	Mon Jul 11 05:31:52 2011	(r223922)
@@ -329,10 +329,9 @@ findstrconst(char **str, const char **va
 		error("unterminated string constant");
 	}
 	p++;
-	size = p - *str;
-	tmp = xmalloc(size + 1);
-	(void) strncpy(tmp, *str, size);
-	tmp[size] = 0;
+	size = p - *str + 1;
+	tmp = xmalloc(size);
+	(void) strlcpy(tmp, *str, size);
 	*val = tmp;
 	*str = p;
 }
@@ -352,13 +351,12 @@ findchrconst(char **str, const char **va
 		error("unterminated string constant");
 	}
 	p++;
-	size = p - *str;
-	if (size != 3) {
+	size = p - *str + 1;
+	if (size != 4) {
 		error("empty char string");
 	}
-	tmp = xmalloc(size + 1);
-	(void) strncpy(tmp, *str, size);
-	tmp[size] = 0;
+	tmp = xmalloc(size);
+	(void) strlcpy(tmp, *str, size);
 	*val = tmp;
 	*str = p;
 }
@@ -381,10 +379,9 @@ findconst(char **str, const char **val)
 			p++;
 		} while (isdigit(*p));
 	}
-	size = p - *str;
-	tmp = xmalloc(size + 1);
-	(void) strncpy(tmp, *str, size);
-	tmp[size] = 0;
+	size = p - *str + 1;
+	tmp = xmalloc(size);
+	(void) strlcpy(tmp, *str, size);
 	*val = tmp;
 	*str = p;
 }
@@ -438,8 +435,7 @@ findkind(char **mark, token *tokp)
 	tokp->kind = TOK_IDENT;
 	for (len = 0; isalnum(str[len]) || str[len] == '_'; len++);
 	tmp = xmalloc(len + 1);
-	(void) strncpy(tmp, str, len);
-	tmp[len] = 0;
+	(void) strlcpy(tmp, str, len + 1);
 	tokp->str = tmp;
 	*mark = str + len;
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201107110531.p6B5Vrfn077306>