From 76384c2568a927c6b864a3b4be52d66cc7127cca Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Wed, 12 Jul 2017 20:14:01 +0200 Subject: [PATCH] Fixed a bug with subtraction in the opcode code --- src/sequencematcher.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sequencematcher.rs b/src/sequencematcher.rs index 2a3da07..bb30cee 100644 --- a/src/sequencematcher.rs +++ b/src/sequencematcher.rs @@ -337,8 +337,8 @@ Opcode::new(String::from("equal"), m.first_start, i, m.second_start, j) if codes.first().unwrap().tag == "equal" { let mut opcode = codes.first_mut().unwrap(); - opcode.first_start = max(opcode.first_start, opcode.first_end - n); - opcode.second_start = max(opcode.second_start, opcode.second_end - n); + opcode.first_start = max(opcode.first_start, opcode.first_end.saturating_sub(n)); + opcode.second_start = max(opcode.second_start, opcode.second_end.saturating_sub(n)); } if codes.last().unwrap().tag == "equal" { let mut opcode = codes.last_mut().unwrap(); @@ -357,8 +357,8 @@ Opcode::new(String::from("equal"), m.first_start, i, m.second_start, j) min(code.second_end, code.second_start + n))); res.push(group.clone()); group.clear(); - first_start = max(first_start, code.first_end - n); - second_start = max(second_start, code.second_end - n); + first_start = max(first_start, code.first_end.saturating_sub(n)); + second_start = max(second_start, code.second_end.saturating_sub(n)); } group.push(Opcode::new(code.tag.clone(), first_start,