From: simon Date: Mon, 20 Feb 2012 07:35:04 +0000 (+0000) Subject: Chris Walker reports that if you give a trailing slash on the pathname X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/agedu/commitdiff_plain/66f0cb51690911c492bba4e94284ccd87c075cf2 Chris Walker reports that if you give a trailing slash on the pathname you tell agedu to scan, it will store that slash in the index and confuse parts of the rest of the code. Strip such slashes off before beginning the scan. git-svn-id: svn://svn.tartarus.org/sgt/agedu@9416 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/du.c b/du.c index 6d26c34..03276c4 100644 --- a/du.c +++ b/du.c @@ -255,9 +255,18 @@ void du(const char *inpath, gotdata_fn_t gotdata, err_fn_t err, size_t pathlen, pathsize; pathlen = strlen(inpath); + + /* + * Trim any trailing slashes from the input path, otherwise we'll + * store them in the index with confusing effects. + */ + while (pathlen > 1 && inpath[pathlen-1] == '/') + pathlen--; + pathsize = pathlen + 256; path = snewn(pathsize, char); - strcpy(path, inpath); + memcpy(path, inpath, pathlen); + path[pathlen] = '\0'; du_recurse(&path, pathlen, &pathsize, gotdata, err, gotdata_ctx, 1); }