summaryrefslogtreecommitdiffstats
path: root/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2015-08-31 11:38:55 -0400
committerTavian Barnes <tavianator@tavianator.com>2015-08-31 11:38:55 -0400
commit0a281f1a541c210fbf7f1e8712b1e50874a82fb9 (patch)
tree44fbb5d227a45d9b06c1c56f5c98ca2edfab6f01 /bftw.c
parente6a306668a5110e59ace562909d9fdd412369656 (diff)
downloadbfs-0a281f1a541c210fbf7f1e8712b1e50874a82fb9.tar.xz
bftw: Fix path size of /.
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] != '/') {