瀏覽代碼

libdpkg: Refactor tar_entry copying into tar_entry_copy()

Guillem Jover 11 年之前
父節點
當前提交
67e532374a
共有 1 個文件被更改,包括 10 次插入3 次删除
  1. 10 3
      lib/dpkg/tarfn.c

+ 10 - 3
lib/dpkg/tarfn.c

@@ -249,6 +249,15 @@ tar_gnu_long(void *ctx, const struct tar_operations *ops, struct tar_entry *te,
 	return status;
 }
 
+static void
+tar_entry_copy(struct tar_entry *dst, struct tar_entry *src)
+{
+	memcpy(dst, src, sizeof(struct tar_entry));
+
+	dst->name = m_strdup(src->name);
+	dst->linkname = m_strdup(src->linkname);
+}
+
 static void
 tar_entry_destroy(struct tar_entry *te)
 {
@@ -335,10 +344,8 @@ tar_extractor(void *ctx, const struct tar_operations *ops)
 			break;
 		case TAR_FILETYPE_SYMLINK:
 			symlink_node = m_malloc(sizeof(*symlink_node));
-			memcpy(&symlink_node->h, &h, sizeof(struct tar_entry));
-			symlink_node->h.name = m_strdup(h.name);
-			symlink_node->h.linkname = m_strdup(h.linkname);
 			symlink_node->next = NULL;
+			tar_entry_copy(&symlink_node->h, &h);
 
 			if (symlink_head)
 				symlink_tail->next = symlink_node;