summaryrefslogtreecommitdiffstats
path: root/bftw.c
diff options
context:
space:
mode:
Diffstat (limited to 'bftw.c')
-rw-r--r--bftw.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/bftw.c b/bftw.c
index d5aad22..9b6f8b3 100644
--- a/bftw.c
+++ b/bftw.c
@@ -233,7 +233,11 @@ static DIR *opendirat(int fd, const char *name) {
* Will hold the full path to the entry, with a trailing '/'.
*/
static int dircache_entry_path(dircache_entry *entry, dynstr *path) {
- size_t pathlen = entry->nameoff + entry->namelen + 1;
+ size_t namelen = entry->namelen;
+ size_t pathlen = entry->nameoff + namelen;
+ if (namelen > 0 && entry->name[namelen - 1] != '/') {
+ ++pathlen;
+ }
if (dynstr_grow(path, pathlen) != 0) {
return -1;
@@ -245,7 +249,7 @@ static int dircache_entry_path(dircache_entry *entry, dynstr *path) {
do {
char *segment = path->str + entry->nameoff;
- size_t namelen = entry->namelen;
+ namelen = entry->namelen;
memcpy(segment, entry->name, namelen);
if (namelen > 0 && entry->name[namelen - 1] != '/') {