[sheepdog] [PATCH 2/2] Move strncpy/strcpy to pstrcpy

Liu Yuan namei.unix at gmail.com
Wed Mar 4 07:49:05 CET 2015


From: Liu Yuan <liuyuan at cmss.chinamobile.com>

Signed-off-by: Liu Yuan <liuyuan at cmss.chinamobile.com>
---
 sheep/cluster/zookeeper.c | 12 ++++++------
 sheep/http/http.c         |  2 +-
 sheep/ops.c               |  4 ++--
 sheepfs/http.c            |  2 +-
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index 4f85043..213bc9e 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -820,7 +820,7 @@ static int zk_get_least_seq(const char *parent, char *least_seq_path,
 		rc = zk_get_data(path, buf, buf_len);
 		switch (rc) {
 		case ZOK:
-			strncpy(least_seq_path, path, path_len);
+			pstrcpy(least_seq_path, path_len, path);
 			return ZOK;
 		case ZNONODE:
 			break;
@@ -1410,10 +1410,10 @@ static int zk_prepare_root(const char *hosts)
 	int i = 0;
 	if (p) {
 		if (strlen(p) >= MAX_NODE_STR_LEN) {
-			strncpy(root, p, MAX_NODE_STR_LEN - 1);
+			pstrcpy(root, MAX_NODE_STR_LEN - 1, p);
 			root[MAX_NODE_STR_LEN - 1] = '\0';
 		} else
-			strcpy(root, p);
+			pstrcpy(root, MAX_NODE_STR_LEN, p);
 		while (hosts != p) {
 			conn[i++] = *hosts++;
 			if (i >= MAX_NODE_STR_LEN - 1)
@@ -1421,12 +1421,12 @@ static int zk_prepare_root(const char *hosts)
 		}
 		conn[i] = '\0';
 	} else {
-		strcpy(root, DEFAULT_BASE);
+		pstrcpy(root, MAX_NODE_STR_LEN, DEFAULT_BASE);
 		if (strlen(hosts) >= MAX_NODE_STR_LEN) {
-			strncpy(conn, hosts, MAX_NODE_STR_LEN - 1);
+			pstrcpy(conn, MAX_NODE_STR_LEN - 1, hosts);
 			conn[MAX_NODE_STR_LEN - 1] = '\0';
 		} else
-			strcpy(conn, hosts);
+			pstrcpy(conn, MAX_NODE_STR_LEN, hosts);
 	}
 
 	if (zk_connect(conn, zk_watcher, zk_timeout) < 0)
diff --git a/sheep/http/http.c b/sheep/http/http.c
index 3f3b5b2..b4d4619 100644
--- a/sheep/http/http.c
+++ b/sheep/http/http.c
@@ -178,7 +178,7 @@ static int request_init_operation(struct http_request *req)
 		if (!left)
 			goto invalid_range;
 		right = strchr(left, '-');
-		strncpy(num, left + sizeof(prefix) - 1, right - left);
+		pstrcpy(num, right - left, left + sizeof(prefix) - 1);
 		req->offset = strtoll(num, &endp, 10);
 		if (num == endp)
 			goto invalid_range;
diff --git a/sheep/ops.c b/sheep/ops.c
index 8084011..403c9b0 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -528,8 +528,8 @@ static int local_stat_cluster(struct request *req)
 			elog->nr_copies = sys->cinfo.nr_copies;
 			elog->copy_policy = sys->cinfo.copy_policy;
 			elog->flags = sys->cinfo.flags;
-			strncpy(elog->drv_name, (char *)sys->cinfo.store,
-				STORE_LEN);
+			pstrcpy(elog->drv_name, STORE_LEN,
+				(char *)sys->cinfo.store);
 		}
 
 		elog->epoch = epoch;
diff --git a/sheepfs/http.c b/sheepfs/http.c
index a750684..b9ded7c 100644
--- a/sheepfs/http.c
+++ b/sheepfs/http.c
@@ -422,7 +422,7 @@ int object_open(const char *path, struct fuse_file_info *fi)
 
 	sem_init(&ch->ready_sem, 0, 0);
 	sem_init(&ch->prepare_sem, 0, 1);
-	strncpy(ch->path, path, PATH_MAX);
+	pstrcpy(ch->path, PATH_MAX, path);
 	ret = pthread_create(&ch->fetch_thread, NULL, fetch_thread_run, ch);
 	if (ret != 0) {
 		sheepfs_pr("failed to create thread to fetch data");
-- 
1.9.1




More information about the sheepdog mailing list