Skip to content

Commit 724ceb6

Browse files
committed
cover special case in combine
1 parent cdbd51f commit 724ceb6

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/combine.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ fn multiply(a: u32, mut b: u32) -> u32 {
2121
}
2222

2323
pub(crate) fn combine(crc1: u32, crc2: u32, len2: u64) -> u32 {
24+
// Special case: If the length of the second chunk is zero, return the hash
25+
// of the first chunk.
26+
if len2 == 0 {
27+
return crc1;
28+
}
29+
2430
// We are padding the first checksum with len2-amount of zeroes. For efficiency,
2531
// this is done in powers-of-two via a lookup table rather than one by one.
2632
let mut p = crc1;
@@ -36,6 +42,7 @@ pub(crate) fn combine(crc1: u32, crc2: u32, len2: u64) -> u32 {
3642

3743
#[test]
3844
fn golden() {
45+
assert_eq!(combine(0x0, 0x1, 0x0), 0x0);
3946
assert_eq!(combine(0xc401f8c9, 0x00000000, 0x0), 0xc401f8c9);
4047
assert_eq!(combine(0x7cba3d5e, 0xe7466d39, 0xb), 0x76365c4f);
4148
assert_eq!(combine(0x576c62d6, 0x123256e1, 0x47), 0x579a636);

0 commit comments

Comments
 (0)