@@ -24,6 +24,12 @@ pub struct CStr8([Char8]);
24
24
25
25
impl CStr8 {
26
26
/// Wraps a raw UEFI string with a safe C string wrapper
27
+ ///
28
+ /// # Safety
29
+ ///
30
+ /// The function will start accessing memory from `ptr` until the first
31
+ /// null byte. It's the callers responsability to ensure `ptr` points to
32
+ /// a valid string, in accessible memory.
27
33
pub unsafe fn from_ptr < ' ptr > ( ptr : * const Char8 ) -> & ' ptr Self {
28
34
let mut len = 0 ;
29
35
while * ptr. add ( len) != NUL_8 {
@@ -47,6 +53,11 @@ impl CStr8 {
47
53
}
48
54
49
55
/// Unsafely creates a C string wrapper from bytes
56
+ ///
57
+ /// # Safety
58
+ ///
59
+ /// It's the callers responsability to ensure chars is a valid Latin-1
60
+ /// null-terminated string, with no interior null bytes.
50
61
pub unsafe fn from_bytes_with_nul_unchecked ( chars : & [ u8 ] ) -> & Self {
51
62
& * ( chars as * const [ u8 ] as * const Self )
52
63
}
@@ -77,6 +88,12 @@ pub struct CStr16([Char16]);
77
88
78
89
impl CStr16 {
79
90
/// Wraps a raw UEFI string with a safe C string wrapper
91
+ ///
92
+ /// # Safety
93
+ ///
94
+ /// The function will start accessing memory from `ptr` until the first
95
+ /// null byte. It's the callers responsability to ensure `ptr` points to
96
+ /// a valid string, in accessible memory.
80
97
pub unsafe fn from_ptr < ' ptr > ( ptr : * const Char16 ) -> & ' ptr Self {
81
98
let mut len = 0 ;
82
99
while * ptr. add ( len) != NUL_16 {
@@ -110,6 +127,11 @@ impl CStr16 {
110
127
}
111
128
112
129
/// Unsafely creates a C string wrapper from a u16 slice.
130
+ ///
131
+ /// # Safety
132
+ ///
133
+ /// It's the callers responsability to ensure chars is a valid UCS-2
134
+ /// null-terminated string, with no interior null bytes.
113
135
pub unsafe fn from_u16_with_nul_unchecked ( codes : & [ u16 ] ) -> & Self {
114
136
& * ( codes as * const [ u16 ] as * const Self )
115
137
}
0 commit comments