aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-09-22 07:52:15 -0500
committerRob Landley <rob@landley.net>2014-09-22 07:52:15 -0500
commit29d30be31123129deac142c6208faa7a1a98b2d0 (patch)
treebc4074bef093643c71b78910fd1e5410970e4192
parentc611c39db47324b9fa6e5cd0f602b3aa3f957ffe (diff)
downloadtoybox-29d30be31123129deac142c6208faa7a1a98b2d0.tar.gz
Respond to two static analysis issues in dirtree_path() reported by Ashwini Sharma.
dirtree->name is an array, not a pointer, so can't be zero. Remove the test. We dereference plen without checking it for null but calling dirtree_path(0, 0) is pilot error: only the _first_ call can have plen = 0. Add a comment.
-rw-r--r--lib/dirtree.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c
index df95e918..60ce56b8 100644
--- a/lib/dirtree.c
+++ b/lib/dirtree.c
@@ -71,12 +71,16 @@ error:
// Return path to this node, assembled recursively.
+// Initial call can pass in NULL to plen, or point to an int initialized to 0
+// to return the length of the path, or a value greater than 0 to allocate
+// extra space if you want to append your own text to the string.
+
char *dirtree_path(struct dirtree *node, int *plen)
{
char *path;
int len;
- if (!node || !node->name) {
+ if (!node) {
path = xmalloc(*plen);
*plen = 0;
return path;