From b61876564c2977a2d776b26dc7a2dcf28ed00bb7 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 12 Oct 2020 22:43:00 -0500 Subject: Fix bug introduced last commit: the if (name) else case needs to zero it. --- lib/dirtree.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/dirtree.c b/lib/dirtree.c index 70b567d2..cc5d0545 100644 --- a/lib/dirtree.c +++ b/lib/dirtree.c @@ -52,14 +52,13 @@ struct dirtree *dirtree_add_node(struct dirtree *parent, char *name, int flags) } // Allocate/populate return structure - dt = xmalloc((len = sizeof(struct dirtree)+len+1)+linklen); - memset(dt, 0, statless ? sizeof(struct dirtree)+1 - : offsetof(struct dirtree, st)); + memset(dt = xmalloc((len = sizeof(struct dirtree)+len+1)+linklen), 0, + statless ? sizeof(struct dirtree)+1 : offsetof(struct dirtree, st)); dt->parent = parent; dt->again = statless ? 2 : 0; if (!statless) memcpy(&dt->st, &st, sizeof(struct stat)); if (name) strcpy(dt->name, name); - else dt->st.st_mode = S_IFDIR; + else *dt->name = 0, dt->st.st_mode = S_IFDIR; if (linklen) dt->symlink = memcpy(len+(char *)dt, libbuf, linklen); return dt; -- cgit v1.2.3