Skip to content

Commit fb1bf10

Browse files
author
Danilo Krummrich
committed
rust: alloc: add missing invariant in Vec::set_len()
When setting a new length, we have to justify that the set length represents the exact number of elements stored in the vector. Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reported-by: Alice Ryhl <aliceryhl@google.com> Closes: https://lore.kernel.org/rust-for-linux/20250311-iov-iter-v1-4-f6c9134ea824@google.com Fixes: 2aac4cd ("rust: alloc: implement kernel `Vec` type") Link: https://lore.kernel.org/r/20250315154436.65065-2-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
1 parent 0af2f6b commit fb1bf10

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

rust/kernel/alloc/kvec.rs

+3
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ where
193193
#[inline]
194194
pub unsafe fn set_len(&mut self, new_len: usize) {
195195
debug_assert!(new_len <= self.capacity());
196+
197+
// INVARIANT: By the safety requirements of this method `new_len` represents the exact
198+
// number of elements stored within `self`.
196199
self.len = new_len;
197200
}
198201

0 commit comments

Comments
 (0)