]> git.hungrycats.org Git - bees/commitdiff
test: fix always-true Fd check in rm_rf
authorZygo Blaxell <bees@furryterror.org>
Sat, 10 Oct 2026 18:50:13 +0000 (14:50 -0400)
committerZygo Blaxell <bees@furryterror.org>
Sat, 10 Oct 2026 18:55:21 +0000 (14:55 -0400)
"if (dir)" converts the Fd to int, so a failed open (-1) is true and
fdopendir(dup(-1)) runs.  Use "!!dir".

The test came in with commit
54d1cb5b63c7aad574a684a81440f0adccbc4fdf
("fd: add safer_path_walk for safer multi-component traversal").

Assisted-by: Claude-Code:claude-opus-5-5
test/fs.cc

index bb30a4cb3323812d4791d042c7eac6e42915d061..b1cd36d4fc043378f406955b654ef5b042a4049a 100644 (file)
@@ -34,7 +34,7 @@ rm_rf(const string &path)
        if (S_ISDIR(st.st_mode)) {
                // Walk children.  Skip "." and ".." by using openat.
                const Fd dir(open(path.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC));
-               if (dir) {
+               if (!!dir) {
                        DIR *d = fdopendir(dup(dir));
                        if (d) {
                                while (auto *e = readdir(d)) {