Skip to content

Commit

Permalink
Merge pull request #365 from armansito/pr-non-zero-buffer-sizes
Browse files Browse the repository at this point in the history
[encoding] Do not allow zero-length buffer sizes
  • Loading branch information
armansito authored Sep 21, 2023
2 parents 56753e0 + 1915e5a commit 530cde9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 6 additions & 1 deletion crates/encoding/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ impl<T: Sized> BufferSize<T> {
/// Creates a new buffer size from number of elements.
pub const fn new(len: u32) -> Self {
Self {
len,
// Each buffer binding must be large enough to hold at least one element to avoid
// triggering validation errors.
//
// Note: not using `Ord::max` here because it doesn't support const eval yet (except
// in nightly)
len: if len > 0 { len } else { 1 },
_phantom: std::marker::PhantomData,
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,8 @@ impl Recording {
impl BufProxy {
pub fn new(size: u64, name: &'static str) -> Self {
let id = Id::next();
BufProxy {
id,
size: size.max(16),
name,
}
debug_assert!(size > 0);
BufProxy { id, size, name }
}
}

Expand Down

0 comments on commit 530cde9

Please sign in to comment.