multi_buffer: Assert char boundary for panic due to point_to_buffer_offset (#40777)

In an attempt to figure out what's wrong with `point_to_buffer_offset`
for crash https://github.com/zed-industries/zed/issues/40453. We want to
know which branch among these two is the bad one.

Release Notes:

- N/A

Co-authored-by: Lukas Wirth <lukas@zed.dev>
This commit is contained in:
Smit Barmase
2025-10-21 19:01:35 +05:30
committed by GitHub
co-authored by Lukas Wirth
parent cad06011c5
commit 10b9ae5e44
3 changed files with 38 additions and 11 deletions
+14 -1
View File
@@ -4454,10 +4454,23 @@ impl MultiBufferSnapshot {
&& region.has_trailing_newline
&& !region.is_main_buffer
{
return Some((&cursor.excerpt()?.buffer, cursor.main_buffer_position()?));
let main_buffer_position = cursor.main_buffer_position()?;
let buffer_snapshot = &cursor.excerpt()?.buffer;
// remove this assert once we figure out the cause of the panics for #40453
buffer_snapshot
.text
.as_rope()
.assert_char_boundary(main_buffer_position);
return Some((buffer_snapshot, main_buffer_position));
} else if buffer_offset > region.buffer.len() {
return None;
}
// remove this assert once we figure out the cause of the panics for #40453
region
.buffer
.text
.as_rope()
.assert_char_boundary(buffer_offset);
Some((region.buffer, buffer_offset))
}