commit 7f358e3b0ea7c7873900dbce1501c56711d7275d from: Stefan Sperling date: Sat Nov 23 21:03:29 2019 UTC eliminate redundant memcpy in got_privsep_send_tree_req() commit - 3fd4eb5ab97dd3b1914bfe46f5b6a7bc1bd1ec81 commit + 7f358e3b0ea7c7873900dbce1501c56711d7275d blob - 0de060802f8b78d6297fc9f7e91c7d607bf57a53 blob + 8d611b1a6422d66a82e9e74240412c54d608896f --- lib/privsep.c +++ lib/privsep.c @@ -269,26 +269,30 @@ got_privsep_send_tree_req(struct imsgbuf *ibuf, int fd struct got_object_id *id, int pack_idx) { const struct got_error *err = NULL; - struct got_imsg_packed_object iobj, *iobjp; - size_t len; + struct ibuf *wbuf; + size_t len = id ? sizeof(struct got_imsg_packed_object) : 0; + + wbuf = imsg_create(ibuf, GOT_IMSG_TREE_REQUEST, 0, 0, len); + if (wbuf == NULL) + return got_error_from_errno("imsg_create TREE_REQUEST"); if (id) { /* tree is packed */ - iobj.idx = pack_idx; - memcpy(iobj.id, id->sha1, sizeof(iobj.id)); - iobjp = &iobj; - len = sizeof(iobj); - } else { - iobjp = NULL; - len = 0; - } + if (imsg_add(wbuf, id->sha1, SHA1_DIGEST_LENGTH) == -1) { + err = got_error_from_errno("imsg_add TREE_ENTRY"); + ibuf_free(wbuf); + return err; + } - if (imsg_compose(ibuf, GOT_IMSG_TREE_REQUEST, 0, 0, fd, iobjp, len) - == -1) { - err = got_error_from_errno("imsg_compose TREE_REQUEST"); - close(fd); - return err; + if (imsg_add(wbuf, &pack_idx, sizeof(pack_idx)) == -1) { + err = got_error_from_errno("imsg_add TREE_ENTRY"); + ibuf_free(wbuf); + return err; + } } + wbuf->fd = fd; + imsg_close(ibuf, wbuf); + return flush_imsg(ibuf); }