Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[encoding] Do not allow zero-length buffer sizes #365

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe len.max(1)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that not the comment directly above?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’ll teach me to read comments. Please ignore :)

_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 @@ -552,11 +552,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