Skip to content

Commit

Permalink
Don't panic in trie_error_val_index either
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Feb 1, 2025
1 parent 5804702 commit cb5b451
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion components/collections/src/codepointtrie/cptrie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ impl<'trie, T: TrieValue> CodePointTrie<'trie, T> {
/// error value.
#[inline(always)] // `always` based on normalizer benchmarking
fn trie_error_val_index(&self) -> u32 {
self.data.len() as u32 - ERROR_VALUE_NEG_DATA_OFFSET
// We use wrapping_sub here to avoid panicky overflow checks.
// len should always be > 1, but if it isn't this will just cause GIGO behavior of producing
// None on `.get()`
debug_assert!(self.data.len() as u32 >= ERROR_VALUE_NEG_DATA_OFFSET);
(self.data.len() as u32).wrapping_sub(ERROR_VALUE_NEG_DATA_OFFSET)
}

fn internal_small_index(&self, code_point: u32) -> u32 {
Expand Down

0 comments on commit cb5b451

Please sign in to comment.