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 <[email protected]> Reported-by: Alice Ryhl <[email protected]> Closes: https://lore.kernel.org/rust-for-linux/[email protected] Fixes: 2aac4cd ("rust: alloc: implement kernel `Vec` type") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Danilo Krummrich <[email protected]>
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

Lines changed: 3 additions & 0 deletions
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)