Skip to content

Commit 0ea5e4d

Browse files
committed
mkasset: fix a bug in inplace margin calculation in Shrinkler
See askeksa/Shrinkler#10
1 parent 9b980cb commit 0ea5e4d

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

tools/common/shrinkler/Verifier.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class LZVerifier : public LZReceiver, public CompressedDataReadListener {
4747
return false;
4848
}
4949
pos += 1;
50+
updateMargin();
5051
return true;
5152
}
5253

@@ -69,6 +70,7 @@ class LZVerifier : public LZReceiver, public CompressedDataReadListener {
6970
}
7071
}
7172
pos += length;
73+
updateMargin();
7274
return true;
7375
}
7476

@@ -79,11 +81,17 @@ class LZVerifier : public LZReceiver, public CompressedDataReadListener {
7981
void read(int index) {
8082
// Another byte of compresed data read
8183
if ((index & (read_size - 1)) == 0) {
82-
int margin = pos - compressed_read_count * read_size;
83-
if (margin > front_overlap_margin) {
84-
front_overlap_margin = margin;
85-
}
86-
compressed_read_count += 1;
84+
compressed_read_count += read_size;
85+
if (compressed_read_count > data_length)
86+
compressed_read_count = data_length;
87+
updateMargin();
88+
}
89+
}
90+
91+
void updateMargin(void) {
92+
int margin = pos - compressed_read_count;
93+
if (margin > front_overlap_margin) {
94+
front_overlap_margin = margin;
8795
}
8896
}
8997
};

0 commit comments

Comments
 (0)