Skip to content

Commit 678d0ed

Browse files
committed
bugfix: read the input data always until the end
In some circumstances the last chunk of input data (max. WIN_OVERLAP=0x1806 bytes) was not read and not analyzed.
1 parent 3d7a803 commit 678d0ed

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/input.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,14 @@ pub fn from_file(sc: &mut ScannerPool, filename: &'static str) -> Result<(), Box
196196
sc.launch_scanner(Some(&filename), &byte_counter, &chunk);
197197
byte_counter += WIN_STEP;
198198
}
199-
// The last is usually shorter
199+
// The last is shorter than WIN_LEN bytes, but can be longer than WIN_STEP
200+
if byte_counter < len {
201+
let chunk = &mmap[byte_counter..len];
202+
sc.launch_scanner(Some(&filename), &byte_counter, &chunk);
203+
byte_counter += WIN_STEP;
204+
}
205+
206+
// Now there can be still some bytes left (maximum WIN_OVERLAP bytes)
200207
if byte_counter < len {
201208
let chunk = &mmap[byte_counter..len];
202209
sc.launch_scanner(Some(&filename), &byte_counter, &chunk);
@@ -242,7 +249,14 @@ fn from_stdin(sc: &mut ScannerPool) -> Result<(), Box<std::io::Error>> {
242249
byte_counter += WIN_STEP;
243250
}
244251
}
245-
// The last is usually shorter
252+
// The last is shorter than WIN_LEN bytes, but can be longer than WIN_STEP
253+
if data_start < data_end {
254+
sc.launch_scanner(None, &byte_counter, &buf[data_start..data_end]);
255+
data_start += WIN_STEP;
256+
byte_counter += WIN_STEP;
257+
}
258+
259+
// Now there can be still some bytes left (maximum WIN_OVERLAP bytes)
246260
if data_start < data_end {
247261
sc.launch_scanner(None, &byte_counter, &buf[data_start..data_end]);
248262
}

0 commit comments

Comments
 (0)