summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2003-07-20 22:16:53 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2003-07-20 22:16:53 +0000
commitc86839a4f38cee5328fdb79f9ad79d34b66162a1 (patch)
tree236b60d271de48fbd71e60dfe034dc6e373532a7 /usr.bin
parentbde6e6316fee250a8f123877fc0964a777299253 (diff)
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
Diffstat (limited to 'usr.bin')
-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;