Skip to content

Commit

Permalink
fix: correct error in the algorithm used for string search
Browse files Browse the repository at this point in the history
  • Loading branch information
jacopodl committed Dec 11, 2023
1 parent 03220b0 commit a9dde1b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions argon/vm/datatype/support/byteops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// Licensed under the Apache License v2.0

#include <algorithm>
#include <cctype>

#include <argon/vm/datatype/support/byteops.h>
Expand Down Expand Up @@ -29,7 +30,7 @@ ArSSize DoSearch(int *table, const unsigned char *buf, ArSize blen, const unsign
while (cursor < blen) {
for (i = 0; i < plen; i++) {
if (buf[cursor - i] != pattern[(plen - 1) - i]) {
cursor = (cursor - i) + table[buf[cursor - i]];
cursor += std::max(1, table[buf[cursor - i]]);
break;
}
}
Expand All @@ -50,7 +51,7 @@ ArSSize DoRSearch(int *table, const unsigned char *buf, ArSize blen, const unsig
while (cursor >= 0) {
for (i = 0; i < plen; i++) {
if (buf[cursor + i] != pattern[i]) {
cursor = cursor - table[buf[cursor - i]];
cursor -= std::max(1, table[buf[cursor - i]]);
break;
}
}
Expand Down

0 comments on commit a9dde1b

Please sign in to comment.