summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-11-21 17:35:27 -0500
committerTavian Barnes <tavianator@tavianator.com>2016-11-21 17:35:27 -0500
commit9b5342ef493521d42953e5f26ea88b58973c6c6a (patch)
tree8e7a60c24f27ecc2e7f9ddafbf5f326c791f35ea
parent40df4d3d4d6389fbec579e555e79e0ca577e342a (diff)
downloadbfs-9b5342ef493521d42953e5f26ea88b58973c6c6a.tar.xz
bftw: Always initialize dircache_entry::{dev,ino}
If stat() fails, they won't get filled in otherwise. Then cycle detection would have read uninitialized values.
-rw-r--r--bftw.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/bftw.c b/bftw.c
index ea683be..cbc9a1b 100644
--- a/bftw.c
+++ b/bftw.c
@@ -222,6 +222,9 @@ static struct dircache_entry *dircache_add(struct dircache *cache, struct dircac
entry->refcount = 1;
entry->fd = -1;
+ entry->dev = -1;
+ entry->ino = -1;
+
memcpy(entry->name, name, namelen);
if (needs_slash) {
entry->name[namelen++] = '/';
@@ -861,12 +864,10 @@ static struct dircache_entry *bftw_add(struct bftw_state *state, const char *nam
return NULL;
}
- if (state->flags & (BFTW_DETECT_CYCLES | BFTW_XDEV)) {
- const struct stat *statbuf = state->ftwbuf.statbuf;
- if (statbuf) {
- entry->dev = statbuf->st_dev;
- entry->ino = statbuf->st_ino;
- }
+ const struct stat *statbuf = state->ftwbuf.statbuf;
+ if (statbuf) {
+ entry->dev = statbuf->st_dev;
+ entry->ino = statbuf->st_ino;
}
return entry;