summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-09-17 12:11:11 -0400
committerTavian Barnes <tavianator@tavianator.com>2017-09-17 12:11:11 -0400
commit5559b9ed33db3e88c6576f1a43ce48b123462e8d (patch)
treeac162579f26144fa9dc637174fafab587a409c90
parent86d790e134d5a12e569e1d78804bc5a54ca9ed25 (diff)
downloadbfs-5559b9ed33db3e88c6576f1a43ce48b123462e8d.tar.xz
opt: Fix -depth with arguments bigger than INT_MAX
-rw-r--r--opt.c12
-rwxr-xr-xtests.sh5
-rw-r--r--tests/test_depth_overflow.out19
3 files changed, 32 insertions, 4 deletions
diff --git a/opt.c b/opt.c
index 717af90..330f804 100644
--- a/opt.c
+++ b/opt.c
@@ -120,14 +120,18 @@ static void debug_opt(const struct opt_state *state, const char *format, ...) {
}
/** Update the inferred mindepth. */
-static void update_mindepth(struct opt_facts *facts, int mindepth) {
+static void update_mindepth(struct opt_facts *facts, long long mindepth) {
if (mindepth > facts->mindepth) {
- facts->mindepth = mindepth;
+ if (mindepth > INT_MAX) {
+ facts->maxdepth = -1;
+ } else {
+ facts->mindepth = mindepth;
+ }
}
}
/** Update the inferred maxdepth. */
-static void update_maxdepth(struct opt_facts *facts, int maxdepth) {
+static void update_maxdepth(struct opt_facts *facts, long long maxdepth) {
if (maxdepth < facts->maxdepth) {
facts->maxdepth = maxdepth;
}
@@ -147,7 +151,7 @@ static void infer_depth_facts(struct opt_state *state, const struct expr *expr)
break;
case CMP_GREATER:
- if (expr->idata == INT_MAX) {
+ if (expr->idata == LONG_LONG_MAX) {
// Avoid overflow
state->facts_when_true.maxdepth = -1;
} else {
diff --git a/tests.sh b/tests.sh
index 983d3b3..6a46ad7 100755
--- a/tests.sh
+++ b/tests.sh
@@ -259,6 +259,7 @@ bsd_tests=(
test_depth_depth_n
test_depth_depth_n_plus
test_depth_depth_n_minus
+ test_depth_overflow
test_gid_name
test_uid_name
test_mnewer
@@ -1148,6 +1149,10 @@ function test_depth_depth_n_minus() {
bfs_diff basic -depth -depth -2
}
+function test_depth_overflow() {
+ bfs_diff basic -depth -4294967296
+}
+
function test_gid_name() {
bfs_diff basic -gid "$(id -gn)"
}
diff --git a/tests/test_depth_overflow.out b/tests/test_depth_overflow.out
new file mode 100644
index 0000000..bb3cd8d
--- /dev/null
+++ b/tests/test_depth_overflow.out
@@ -0,0 +1,19 @@
+basic
+basic/a
+basic/b
+basic/c
+basic/e
+basic/g
+basic/i
+basic/j
+basic/k
+basic/l
+basic/c/d
+basic/e/f
+basic/g/h
+basic/j/foo
+basic/k/foo
+basic/l/foo
+basic/k/foo/bar
+basic/l/foo/bar
+basic/l/foo/bar/baz