summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/color.c19
-rw-r--r--tests/bfs/color_notdir_slash_error.out0
-rw-r--r--tests/bfs/color_notdir_slash_error.sh2
3 files changed, 13 insertions, 8 deletions
diff --git a/src/color.c b/src/color.c
index d1b36f9..a701813 100644
--- a/src/color.c
+++ b/src/color.c
@@ -998,22 +998,25 @@ static ssize_t first_broken_offset(const char *path, const struct BFTW *ftwbuf,
goto out;
}
+ size_t len = dstrlen(at_path);
while (ret > 0) {
+ dstresize(&at_path, len);
if (xfaccessat(at_fd, at_path, F_OK) == 0) {
break;
}
- size_t len = dstrlen(at_path);
- while (ret && at_path[len - 1] == '/') {
- --len, --ret;
- }
- if (errno != ENOTDIR) {
- while (ret && at_path[len - 1] != '/') {
+ // Try without trailing slashes, to distinguish "notdir/" from "notdir"
+ if (at_path[len - 1] == '/') {
+ do {
--len, --ret;
- }
+ } while (ret > 0 && at_path[len - 1] == '/');
+ continue;
}
- dstresize(&at_path, len);
+ // Remove the last component and try again
+ do {
+ --len, --ret;
+ } while (ret > 0 && at_path[len - 1] != '/');
}
out_path:
diff --git a/tests/bfs/color_notdir_slash_error.out b/tests/bfs/color_notdir_slash_error.out
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/bfs/color_notdir_slash_error.out
diff --git a/tests/bfs/color_notdir_slash_error.sh b/tests/bfs/color_notdir_slash_error.sh
new file mode 100644
index 0000000..ca26d50
--- /dev/null
+++ b/tests/bfs/color_notdir_slash_error.sh
@@ -0,0 +1,2 @@
+# Regression test: infinite loop printing the error message for .../notdir/nowhere
+! bfs_diff -color links/notdir/nowhere