Skip to content

Commit f012064

Browse files
committed
multiboot2: StringError::MissingNull => StringError::MissingNul
This aligns the name with the inner error. In the codebase, however, we use "null". NUL often refers to the ANSI character `0`/NUL and null or NULL to a zero pointer, i.e., to nothing. For now, we keep null everywhere except for the StringError::MissingNul.
1 parent 9ee178a commit f012064

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Diff for: multiboot2/src/tag.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use core::str::Utf8Error;
1212
#[derive(Debug, PartialEq, Eq, Clone)]
1313
pub enum StringError {
1414
/// There is no terminating null-byte, although the spec requires one.
15-
MissingNull(core::ffi::FromBytesUntilNulError),
15+
MissingNul(core::ffi::FromBytesUntilNulError),
1616
/// The sequence until the first NULL byte is not valid UTF-8.
1717
Utf8(Utf8Error),
1818
}
@@ -27,7 +27,7 @@ impl Display for StringError {
2727
impl core::error::Error for StringError {
2828
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
2929
match self {
30-
StringError::MissingNull(e) => Some(e),
30+
StringError::MissingNul(e) => Some(e),
3131
StringError::Utf8(e) => Some(e),
3232
}
3333
}
@@ -66,8 +66,7 @@ impl Tag {
6666
/// Parses the provided byte sequence as Multiboot string, which maps to a
6767
/// [`str`].
6868
pub fn parse_slice_as_string(bytes: &[u8]) -> Result<&str, StringError> {
69-
let cstr =
70-
core::ffi::CStr::from_bytes_until_nul(bytes).map_err(StringError::MissingNull)?;
69+
let cstr = core::ffi::CStr::from_bytes_until_nul(bytes).map_err(StringError::MissingNul)?;
7170

7271
cstr.to_str().map_err(StringError::Utf8)
7372
}
@@ -148,7 +147,7 @@ mod tests {
148147
// empty slice is invalid
149148
assert!(matches!(
150149
Tag::parse_slice_as_string(&[]),
151-
Err(StringError::MissingNull(_))
150+
Err(StringError::MissingNul(_))
152151
));
153152
// empty string is fine
154153
assert_eq!(Tag::parse_slice_as_string(&[0x00]), Ok(""));
@@ -160,7 +159,7 @@ mod tests {
160159
// reject missing null
161160
assert!(matches!(
162161
Tag::parse_slice_as_string(b"hello"),
163-
Err(StringError::MissingNull(_))
162+
Err(StringError::MissingNul(_))
164163
));
165164
// must not include final null
166165
assert_eq!(Tag::parse_slice_as_string(b"hello\0"), Ok("hello"));

0 commit comments

Comments
 (0)