I was going to push this test, but then I realized this behavior was
probably an unintentional consequence of Paul's commit to prefer
signed types [1]. So perhaps it is better to check that --max-depth is
positive, i.e., make this change instead:
diff --git a/src/du.c b/src/du.c
index bff1b6672..8d99c4265 100644
--- a/src/du.c
+++ b/src/du.c
@@ -860,7 +860,7 @@ main (int argc, char **argv)
{
intmax_t tmp;
if (xstrtoimax (optarg, NULL, 0, &tmp, "") == LONGINT_OK
- && tmp <= IDX_MAX)
+ && 0 <= tmp && tmp <= IDX_MAX)
{
max_depth_specified = true;
max_depth = tmp;
Thoughts?
[1]
https://github.com/coreutils/coreutils/commit/e20d63c442b0365cc1a7cb236a63412523784e0a
--- 8< ---
* tests/du/max-depth.sh: Test the behavior of --max-depth=-1.
---
tests/du/max-depth.sh | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/tests/du/max-depth.sh b/tests/du/max-depth.sh
index 8684379eb..616e12405 100755
--- a/tests/du/max-depth.sh
+++ b/tests/du/max-depth.sh
@@ -36,4 +36,11 @@ cut -f2- out > k && mv k out
compare exp out || fail=1
compare /dev/null err || fail=1
+# Repeat, but us -d -1.
+printf 'a\n' > exp || framework_failure_
+du -d -1 a > out 2>err || fail=1
+cut -f2- out > k && mv k out
+compare exp out || fail=1
+compare /dev/null err || fail=1
+
Exit $fail
--
2.55.0