Skip to content

Commit

Permalink
Add debug assertions for the start and len invariants
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdrz committed Jan 23, 2024
1 parent eb086c4 commit 6547452
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/exec/use_pty/pipe/ring_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ impl RingBuffer {

self.len += inserted_len;

debug_assert!(self.start < Self::LEN);
debug_assert!(self.len <= Self::LEN);

Ok(inserted_len)
}

Expand Down Expand Up @@ -82,10 +85,13 @@ impl RingBuffer {
};

self.start += removed_len;
self.start %= self.storage.len();
self.start %= Self::LEN;

self.len -= removed_len;

debug_assert!(self.start < Self::LEN);
debug_assert!(self.len <= Self::LEN);

Ok(removed_len)
}
}
Expand Down

0 comments on commit 6547452

Please sign in to comment.