diff options
author | Rob Landley <rob@landley.net> | 2020-10-12 22:43:00 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-10-12 22:43:00 -0500 |
commit | b61876564c2977a2d776b26dc7a2dcf28ed00bb7 (patch) | |
tree | 232737c34cd9f81440bc29ed43f95d7d3912550e | |
parent | 67bd0be1a4ed817954c9dcededf9bd9cb8c2f431 (diff) | |
download | toybox-b61876564c2977a2d776b26dc7a2dcf28ed00bb7.tar.gz |
Fix bug introduced last commit: the if (name) else case needs to zero it.
-rw-r--r-- | lib/dirtree.c | 7 |
1 files changed, 3 insertions, 4 deletions
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; |