From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id BCC551384B4 for ; Thu, 26 Nov 2015 08:00:51 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2385921C01B; Thu, 26 Nov 2015 08:00:46 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 9584721C01B for ; Thu, 26 Nov 2015 08:00:45 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 638FA33BE19 for ; Thu, 26 Nov 2015 08:00:44 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id CE5A89AE for ; Thu, 26 Nov 2015 08:00:40 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1448524701.a30baf6e2163eb4ed4dd6c9b5beee2473c775377.vapier@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: qdepends.c X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: a30baf6e2163eb4ed4dd6c9b5beee2473c775377 X-VCS-Branch: master Date: Thu, 26 Nov 2015 08:00:40 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 64c3b00d-4ebe-43da-bebc-ec92cd7abf0f X-Archives-Hash: 1143d5e285e356c3158e94c9711fee5c commit: a30baf6e2163eb4ed4dd6c9b5beee2473c775377 Author: Mike Frysinger gentoo org> AuthorDate: Thu Nov 26 07:58:21 2015 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Thu Nov 26 07:58:21 2015 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=a30baf6e qdepends: rework dep tree flattening By leveraging stpcpy, we don't need to call strlen at all, or update the length of the buffer we've written to. Instead, make the func recursive and pass around the start of the buffer that is ready to accept more data. While we're here, increase the static buffer to 1MiB. Some packages (e.g. qemu) are larger than the 8KiB we have which causes corruption/crashes. There's no way we'd exceed 1MiB! qdepends.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/qdepends.c b/qdepends.c index bcdeaa5..5ded84b 100644 --- a/qdepends.c +++ b/qdepends.c @@ -70,7 +70,6 @@ _q_static void _dep_print_tree(FILE *fp, const dep_node *root, size_t space); void dep_burn_tree(dep_node *root); char *dep_flatten_tree(const dep_node *root); _q_static void _dep_attach(dep_node *root, dep_node *attach_me, int type); -_q_static void _dep_flatten_tree(const dep_node *root, char *buf, size_t *pos); _q_static void _dep_burn_node(dep_node *node); int qdepends_main_vdb(const char *depend_file, int argc, char **argv); int qdepends_vdb_deep(const char *depend_file, const char *query); @@ -352,33 +351,33 @@ _q_static void dep_prune_use(dep_node *root, const char *use) if (root->children) dep_prune_use(root->children, use); } -void _dep_flatten_tree(const dep_node *root, char *buf, size_t *pos) +_q_static char * +_dep_flatten_tree(const dep_node *root, char *buf) { if (root->type == DEP_NULL) goto this_node_sucks; if (root->type == DEP_NORM) { - size_t len = strlen(root->info); - memcpy(buf + *pos, root->info, len); - *pos += len+1; - buf[*pos-1] = ' '; + buf[0] = ' '; + buf = stpcpy(buf + 1, root->info); } - if (root->children) _dep_flatten_tree(root->children, buf, pos); + if (root->children) + buf = _dep_flatten_tree(root->children, buf); this_node_sucks: - if (root->neighbor) _dep_flatten_tree(root->neighbor, buf, pos); + if (root->neighbor) + buf = _dep_flatten_tree(root->neighbor, buf); + return buf; } char *dep_flatten_tree(const dep_node *root) { - static char flat[8192]; - size_t pos = 0; - _dep_flatten_tree(root, flat, &pos); - if (pos == 0) { + static char flat[1024 * 1024]; + char *buf = _dep_flatten_tree(root, flat); + if (buf == flat) { /* all the nodes were squashed ... for example: * USE=-selinux RDEPEND="selinux? ( sys-libs/libselinux )" */ return NULL; } - flat[pos-1] = '\0'; - return flat; + return flat + 1; } struct qdepends_opt_state {