Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix chunks peek_with_bitmaps panic (#38430)

Anthony Eid55d130a166d4
diff --git a/crates/rope/src/rope.rs b/crates/rope/src/rope.rs
index 3f6addb7c23..9c98985989c 100644
--- a/crates/rope/src/rope.rs
+++ b/crates/rope/src/rope.rs
@@ -784,7 +784,10 @@ impl<'a> Chunks<'a> {
slice_start..slice_end
};
- let bitmask = (1u128 << slice_range.end as u128).saturating_sub(1);
+ // slice range has a bounds between 0 and 128 in non test builds
+ // We use a non wrapping sub because we want to overflow in the case where slice_range.end == 128
+ // because that represents a full chunk and the bitmask shouldn't remove anything
+ let bitmask = (1u128.unbounded_shl(slice_range.end as u32)).wrapping_sub(1);
let chars = (chunk.chars() & bitmask) >> slice_range.start;
let tabs = (chunk.tabs & bitmask) >> slice_range.start;