summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--find-bytes.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/find-bytes.c b/find-bytes.c
index 6e5af9c..8415d4d 100644
--- a/find-bytes.c
+++ b/find-bytes.c
@@ -75,7 +75,9 @@ void find_key(FILE *fp, char *key, size_t key_len) {
while (next_p && end_p >= next_p + key_len) {
next_p = memmem(next_p, end_p - next_p, key, key_len);
if (next_p) {
- size_t offset = (next_p - buf_start) + position;
+ /* if there is an overlap with the previous chunk, then the
+ * offset may be smaller than position. */
+ size_t offset = position + (next_p - new_data_p);
printf(as_hex ? "%zx\n" : "%zi\n", offset);
next_p += key_len;
}