rust: alloc: use `if` instead of `match` in VecExt<T>::reserve()
Subsystems (2)
PATCH 1/1 rust: alloc: use `if` instead of `match` in VecExt<T>::reserve()
In commit 1161057f53f6 ("rust: alloc: fix dangling pointer in VecExt<T>::reserve()") the check for zero of a vector's capacity has been implemented using a match statement. Using an if statement is the preferred style, hence change that.
---
Sending a separate patch since v3 has been merged [1] already.
Please feel free to melt this patch into the original commit.
--- rust/kernel/alloc/vec_ext.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
rust/kernel/alloc/vec_ext.rs +1 -4
@@ -141,10 +141,7 @@ fn reserve(&mut self, additional: usize, flags: Flags) -> Result<(), AllocError>// `krealloc_aligned`. A `Vec<T>`'s `ptr` value is not guaranteed to be NULL and might be // dangling after being created with `Vec::new`. Instead, we can rely on `Vec<T>`'s capacity // to be zero if no memory has been allocated yet. -let ptr =match cap { -0 => ptr::null_mut (), - _ => old_ptr, - }; +let ptr =if cap ==0 { ptr::null_mut () }else { old_ptr };// SAFETY: `ptr` is valid because it's either NULL or comes from a previous call to // `krealloc_aligned`. We also verified that the type is not a ZST.
base-commit: 1161057f53f643b63060835d46461ef09e8abe2f
Signature · 1 line
2.44.0
Miguel Ojeda
AppliedQuoted 8 lines · Danilo Krummrich
In commit
1161057f53f6("rust: alloc: fix dangling pointer in VecExt<T>::reserve()") the check for zero of a vector's capacity has been implemented using amatchstatement. Using anifstatement is the preferred style, hence change that.
Applied to rust-next as fixup for "[PATCH v3] rust: alloc: fix dangling pointer in VecExt<T>::reserve()" -- thanks!
Cheers,
Miguel