diff options
author | Rob Landley <rob@landley.net> | 2020-10-03 00:26:12 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-10-03 00:26:12 -0500 |
commit | 424632aaa30e85e069678da8c413a35c4d321cf6 (patch) | |
tree | 874843c18ee79ce1ae9de6c326edcd1820d64a1e /lib | |
parent | f570a02c6c544b9d8f277c43506cdde92d947d73 (diff) | |
download | toybox-424632aaa30e85e069678da8c413a35c4d321cf6.tar.gz |
Non-recursive dirtree_path() needs to return start of allocation
when passed in extra allocation length or else free() gets very unhappy.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dirtree.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c index 02f4b887..9712ee14 100644 --- a/lib/dirtree.c +++ b/lib/dirtree.c @@ -85,12 +85,13 @@ char *dirtree_path(struct dirtree *node, int *plen) { struct dirtree *nn; char *path; - int len = plen ? *plen : 0; + int ll, len; + ll = len = plen ? *plen : 0; for (nn = node; nn; nn = nn->parent) if (*nn->name) len += strlen(nn->name)+1; if (plen) *plen = len; if (!len) return 0; - path = xmalloc(len)+len; + path = xmalloc(len)+len-ll; for (nn = node; nn; nn = nn->parent) if ((len = strlen(nn->name))) { *--path = '/'*(nn != node); memcpy(path -= len, nn->name, len); |