From 80f3173fbd27e919f2b295964067e48a8030d4c2 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 16 Dec 2021 10:23:45 -0800 Subject: [PATCH] Always panic if invalid point is passed to {prev,next}_row_boundary Co-Authored-By: Antonio Scandurra --- crates/editor/src/display_map.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index 10e27309d5..e1f7f473a8 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -204,7 +204,8 @@ impl DisplaySnapshot { self.buffer_snapshot.max_point().row + 1 } - pub fn prev_row_boundary(&self, mut display_point: DisplayPoint) -> (DisplayPoint, Point) { + pub fn prev_row_boundary(&self, input_display_point: DisplayPoint) -> (DisplayPoint, Point) { + let mut display_point = input_display_point; loop { *display_point.column_mut() = 0; let mut point = display_point.to_point(self); @@ -214,17 +215,15 @@ impl DisplaySnapshot { if next_display_point == display_point { return (display_point, point); } - debug_assert!( - next_display_point < display_point, - "{:?} > {:?}", - next_display_point, - display_point - ); + if next_display_point > display_point { + panic!("invalid display point {:?}", input_display_point); + } display_point = next_display_point; } } - pub fn next_row_boundary(&self, mut display_point: DisplayPoint) -> (DisplayPoint, Point) { + pub fn next_row_boundary(&self, input_display_point: DisplayPoint) -> (DisplayPoint, Point) { + let mut display_point = input_display_point; loop { *display_point.column_mut() = self.line_len(display_point.row()); let mut point = self.display_point_to_point(display_point, Bias::Right); @@ -234,12 +233,9 @@ impl DisplaySnapshot { if next_display_point == display_point { return (display_point, point); } - debug_assert!( - next_display_point > display_point, - "{:?} < {:?}", - next_display_point, - display_point - ); + if next_display_point < display_point { + panic!("invalid display point {:?}", input_display_point); + } display_point = next_display_point; } }