Skip to content

Commit 9fc0ac8

Browse files
committed
Fix potential overflow bug.
1 parent e43ed77 commit 9fc0ac8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/dfa.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,12 @@ use sparse::SparseSet;
6666
pub fn can_exec(insts: &Program) -> bool {
6767
use prog::Inst::*;
6868
// If for some reason we manage to allocate a regex program with more
69-
// than u32::MAX instructions, then we can't execute the DFA because we
70-
// use 32 bit instruction pointers for memory savings.
71-
if insts.len() > ::std::u32::MAX as usize {
69+
// than i32::MAX instructions, then we can't execute the DFA because we
70+
// use 32 bit instruction pointer deltas for memory savings.
71+
// If i32::MAX is the largest positive delta,
72+
// then -i32::MAX == i32::MIN + 1 is the largest negative delta,
73+
// and we are OK to use 32 bits.
74+
if insts.len() > ::std::i32::MAX as usize {
7275
return false;
7376
}
7477
for inst in insts {

0 commit comments

Comments
 (0)