Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: overflow in qgrams for k=32 #478

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Expand Up @@ -92,11 +92,11 @@ jobs:
- name: Install MSRV toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.51.0
toolchain: 1.53.0
override: true

- name: check if README matches MSRV defined here
run: grep '1.51.0' README.md
run: grep '1.53.0' README.md

- name: Run tests
uses: actions-rs/cargo@v1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -57,7 +57,7 @@ For extra credit, feel free to familiarize yourself with:

## Minimum supported Rust version

Currently the minimum supported Rust version is 1.51.0.
Currently the minimum supported Rust version is 1.53.0.

## License

Expand Down
11 changes: 10 additions & 1 deletion src/alphabets/mod.rs
Expand Up @@ -326,7 +326,7 @@ impl RankTransform {
text: text.into_iter(),
ranks: self,
bits,
mask: (1 << (q * bits)) - 1,
mask: 1usize.checked_shl(q * bits).unwrap_or(0).wrapping_sub(1),
qgram: 0,
};

Expand Down Expand Up @@ -448,4 +448,13 @@ mod tests {
assert_eq!(Alphabet::new(b"ATCG"), Alphabet::new(b"TAGC"));
assert_ne!(Alphabet::new(b"ATCG"), Alphabet::new(b"ATC"));
}

/// When `q * bits == usize::BITS`, make sure that `1<<(1*bits)` does not overflow.
#[test]
fn test_qgram_shiftleft_overflow() {
let alphabet = Alphabet::new(b"ACTG");
let transform = RankTransform::new(&alphabet);
let text = b"ACTG".repeat(100);
transform.qgrams(usize::BITS / 2, text);
}
}