X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/agedu/blobdiff_plain/352f37e2de014cc666d8323167aa887ddf529cdc..256c29a27ba79677a78bc676a3cc73ee1aad2d68:/du.c diff --git a/du.c b/du.c index da16e53..88edd27 100644 --- a/du.c +++ b/du.c @@ -114,7 +114,16 @@ static void du_recurse(char **path, size_t pathlen, size_t *pathsize, *pathsize = newpathlen * 3 / 2 + 256; *path = sresize(*path, *pathsize, char); } - sprintf(*path + pathlen, "/%s", names[i]); + /* + * Avoid duplicating a slash if we got a trailing one to + * begin with (i.e. if we're starting the scan in '/' itself). + */ + if (pathlen > 0 && (*path)[pathlen-1] == '/') { + strcpy(*path + pathlen, names[i]); + newpathlen--; + } else { + sprintf(*path + pathlen, "/%s", names[i]); + } du_recurse(path, newpathlen, pathsize, gotdata, gotdata_ctx);