summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2003-07-20 22:16:52 +0000
committermillert <millert@openbsd.org>2003-07-20 22:16:52 +0000
commit884101901d0eb83e8f6015c38dc0c5806407c236 (patch)
treef19f1006db048c79cf25456af594e694e2d6eee6
parentfix (diff)
downloadwireguard-openbsd-884101901d0eb83e8f6015c38dc0c5806407c236.tar.xz
wireguard-openbsd-884101901d0eb83e8f6015c38dc0c5806407c236.zip
After some discussion on icb it seems a do {} while is what we want
after all since there's no need to check an invariant the first time through. I've fixed the loop invariants (we need to take special care with the "j == fg->patternLen" case) and hopefully made things a tad bit clearer. tedu@ OK
-rw-r--r--usr.bin/grep/util.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
index 744a211d8ed..97af83c9eca 100644
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.16 2003/07/20 19:19:48 millert Exp $ */
+/* $OpenBSD: util.c,v 1.17 2003/07/20 22:16:52 millert Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -400,8 +400,8 @@ grep_search(fastgrep_t *fg, unsigned char *data, int dataLen, regmatch_t *pmatch
}
} else if (fg->reversedSearch) {
/* Quick Search algorithm. */
- for (j = dataLen; j >= fg->patternLen;
- j -= fg->qsBc[data[j - fg->patternLen - 1]]) {
+ j = dataLen;
+ do {
if (grep_cmp(fg->pattern, data + j - fg->patternLen,
fg->patternLen) == -1) {
rtrnVal = 0;
@@ -409,7 +409,11 @@ grep_search(fastgrep_t *fg, unsigned char *data, int dataLen, regmatch_t *pmatch
pmatch->rm_eo = j;
break;
}
- }
+ /* Shift if within bounds, otherwise, we are done. */
+ if (j == fg->patternLen)
+ break;
+ j -= fg->qsBc[data[j - fg->patternLen - 1]];
+ } while (j >= fg->patternLen);
} else {
/* Quick Search algorithm. */
j = 0;