aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/search.c4
-rw-r--r--tests/testsuite.at1
2 files changed, 3 insertions, 2 deletions
diff --git a/src/search.c b/src/search.c
index ffa3a99..0df483f 100644
--- a/src/search.c
+++ b/src/search.c
@@ -783,8 +783,8 @@ teco_do_search_backwards(regex_t *re, gsize from, gsize to, gint *count, GError
gsize to_block = to-from;
while (to_block > 0) {
- gsize from_block = teco_search_block_size > 0
- ? MAX(0, to_block - teco_search_block_size) : 0;
+ gsize from_block = teco_search_block_size > 0 && to_block >= teco_search_block_size
+ ? to_block - teco_search_block_size : 0;
/* how many bytes have been consumed in the current block */
gsize offset = 0;
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 98425d1..0f7e32b 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -537,6 +537,7 @@ TE_CHECK([[100000<@I"^J">J @S"^EM^X"]], 0, ignore, ignore)
AT_CLEANUP
AT_SETUP([Block-wise backwards search])
+TE_CHECK([[@I/ABCD/ -:@S/A/"F(0/0)']], 0, ignore, ignore)
# Failed when using GRegex (PCRE), which had broken support for partial matches.
# This is not an issue with terex.
TE_CHECK([[2,8EJ @I/ABCD/ -:@S/BC/"F(0/0)' .-3"N(0/0)' ^S+2"N(0/0)']], 0, ignore, ignore)