From 670ebd97fb431e830b1500b2e7e8013b121fb2c5 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 31 Jan 2024 20:58:43 -0500 Subject: bftw: Actually stop if the callback returns BFTW_STOP Otherwise, bftw_ids() or bftw_eds() might keep going! Fixes: 5f16169 ("bftw: Share the bftw_state between iterations of ids/eds") --- src/bftw.c | 2 +- tests/bsd/s_quit.out | 1 + tests/bsd/s_quit.sh | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 tests/bsd/s_quit.out create mode 100644 tests/bsd/s_quit.sh diff --git a/src/bftw.c b/src/bftw.c index ab930f1..c9ba67e 100644 --- a/src/bftw.c +++ b/src/bftw.c @@ -1791,7 +1791,7 @@ static int bftw_impl(struct bftw_state *state) { break; } if (bftw_visit(state, NULL) != 0) { - break; + return -1; } } diff --git a/tests/bsd/s_quit.out b/tests/bsd/s_quit.out new file mode 100644 index 0000000..5ea492b --- /dev/null +++ b/tests/bsd/s_quit.out @@ -0,0 +1 @@ +basic/j/foo diff --git a/tests/bsd/s_quit.sh b/tests/bsd/s_quit.sh new file mode 100644 index 0000000..6bd55ab --- /dev/null +++ b/tests/bsd/s_quit.sh @@ -0,0 +1,4 @@ +# Regression test: bfs -S ids -s -name foo -quit would not actually quit, +# ending up in a confused state and erroring/crashing + +bfs_diff -s basic -name foo -print -quit -- cgit v1.2.3