Commit c0588d8daffdb2d2fcb890bd580ca20ec3c646a6

Stefan Sperling 2018-11-07T08:00:51

avoid unnecessary memcpy in got_privsep_recv_tree()

diff --git a/lib/privsep.c b/lib/privsep.c
index eac5aa1..6923219 100644
--- a/lib/privsep.c
+++ b/lib/privsep.c
@@ -684,7 +684,7 @@ get_more:
 		struct imsg imsg;
 		size_t n;
 		size_t datalen;
-		struct got_imsg_tree_entry ite;
+		struct got_imsg_tree_entry *ite;
 		struct got_tree_entry *te = NULL;
 
 		n = imsg_get(ibuf, &imsg);
@@ -728,18 +728,18 @@ get_more:
 				err = got_error(GOT_ERR_PRIVSEP_MSG);
 				break;
 			}
-			if (datalen < sizeof(ite) || datalen > MAX_IMSGSIZE) {
+			if (datalen < sizeof(*ite) || datalen > MAX_IMSGSIZE) {
 				err = got_error(GOT_ERR_PRIVSEP_LEN);
 				break;
 			}
 
 			/* Remaining data contains the entry's name. */
-			datalen -= sizeof(ite);
-			memcpy(&ite, imsg.data, sizeof(ite));
+			datalen -= sizeof(*ite);
 			if (datalen == 0 || datalen > MAX_IMSGSIZE) {
 				err = got_error(GOT_ERR_PRIVSEP_LEN);
 				break;
 			}
+			ite = imsg.data;
 
 			te = got_alloc_tree_entry_partial();
 			if (te == NULL) {
@@ -752,11 +752,11 @@ get_more:
 				err = got_error_from_errno();
 				break;
 			}
-			memcpy(te->name, imsg.data + sizeof(ite), datalen);
+			memcpy(te->name, imsg.data + sizeof(*ite), datalen);
 			te->name[datalen] = '\0';
 
-			memcpy(te->id->sha1, ite.id, SHA1_DIGEST_LENGTH);
-			te->mode = ite.mode;
+			memcpy(te->id->sha1, ite->id, SHA1_DIGEST_LENGTH);
+			te->mode = ite->mode;
 			SIMPLEQ_INSERT_TAIL(&(*tree)->entries.head, te, entry);
 			nentries++;
 			break;