@@ -15,7 +15,8 @@ use uefi_raw::table::boot::MemoryDescriptor;
15
15
16
16
#[ cfg( feature = "alloc" ) ]
17
17
use {
18
- crate :: mem:: make_boxed, crate :: Guid , alloc:: borrow:: ToOwned , alloc:: boxed:: Box , alloc:: vec:: Vec ,
18
+ crate :: mem:: make_boxed, crate :: CString16 , crate :: Guid , alloc:: borrow:: ToOwned ,
19
+ alloc:: boxed:: Box , alloc:: vec:: Vec ,
19
20
} ;
20
21
21
22
#[ cfg( all( feature = "unstable" , feature = "alloc" ) ) ]
@@ -303,15 +304,13 @@ impl Iterator for VariableKeys {
303
304
304
305
match result {
305
306
Ok ( ( ) ) => {
306
- // Copy the name buffer, truncated after the first null
307
- // character (if one is present).
308
- let name = if let Some ( nul_pos) = self . name . iter ( ) . position ( |c| * c == 0 ) {
309
- self . name [ ..=nul_pos] . to_owned ( )
310
- } else {
311
- self . name . clone ( )
307
+ // Convert the name to a `CStr16`, yielding an error if invalid.
308
+ let Ok ( name) = CStr16 :: from_u16_until_nul ( & self . name ) else {
309
+ return Some ( Err ( Status :: UNSUPPORTED . into ( ) ) ) ;
312
310
} ;
311
+
313
312
Some ( Ok ( VariableKey {
314
- name,
313
+ name : name . to_owned ( ) ,
315
314
vendor : self . vendor ,
316
315
} ) )
317
316
}
@@ -868,30 +867,26 @@ impl TryFrom<&[u8]> for Time {
868
867
#[ cfg( feature = "alloc" ) ]
869
868
#[ derive( Clone , Debug , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
870
869
pub struct VariableKey {
871
- pub ( crate ) name : Vec < u16 > ,
872
870
/// Unique identifier for the vendor.
873
871
pub vendor : VariableVendor ,
872
+
873
+ /// Name of the variable, unique with the vendor namespace.
874
+ pub name : CString16 ,
874
875
}
875
876
876
877
#[ cfg( feature = "alloc" ) ]
877
878
impl VariableKey {
878
879
/// Name of the variable.
880
+ #[ deprecated = "Use the VariableKey.name field instead" ]
879
881
pub fn name ( & self ) -> core:: result:: Result < & CStr16 , crate :: data_types:: FromSliceWithNulError > {
880
- CStr16 :: from_u16_with_nul ( & self . name )
882
+ Ok ( & self . name )
881
883
}
882
884
}
883
885
884
886
#[ cfg( feature = "alloc" ) ]
885
887
impl Display for VariableKey {
886
888
fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
887
- write ! ( f, "VariableKey {{ name: " ) ?;
888
-
889
- match self . name ( ) {
890
- Ok ( name) => write ! ( f, "\" {name}\" " ) ?,
891
- Err ( err) => write ! ( f, "Err({err:?})" ) ?,
892
- }
893
-
894
- write ! ( f, ", vendor: " ) ?;
889
+ write ! ( f, "VariableKey {{ name: \" {}\" , vendor: " , self . name) ?;
895
890
896
891
if self . vendor == VariableVendor :: GLOBAL_VARIABLE {
897
892
write ! ( f, "GLOBAL_VARIABLE" ) ?;
0 commit comments