summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-05-08 12:54:09 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-05-08 12:54:09 +0200
commit80172b86edfb4a46a26de13c741a8da97d1b7713 (patch)
tree7f2ed573067715e5cc0e69165cdbcd99f28d2339
parent6937908478c7ffd19b255e0dc0d5c2e43fa0ec54 (diff)
downloadc-files-80172b86edfb4a46a26de13c741a8da97d1b7713.tar.gz
c-files: fix offset calculation for overlap
-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;
}