This commit is contained in:
gnzlbg 2018-11-09 10:49:59 +01:00 committed by gnzlbg
parent 491551e09a
commit 8b54b6f9d5
5 changed files with 35 additions and 9 deletions

View File

@ -40,7 +40,10 @@ impl fmt::Debug for Error {
small; in this case as much data as possible are read \
despite the error."
),
libc::ENOENT => write!(f, "`name` or `mib` specifies an unknown/invalid value."),
libc::ENOENT => write!(
f,
"`name` or `mib` specifies an unknown/invalid value."
),
libc::EPERM => write!(
f,
"Attempt to read or write `void` value, or attempt to \

View File

@ -110,7 +110,9 @@ impl Name {
| b"thread.prof.name"
| b"prof.dump" => true,
v if v.starts_with(b"arena.") && v.ends_with(b".dss") => true,
v if v.starts_with(b"stats.arenas.") && v.ends_with(b".dss") => true,
v if v.starts_with(b"stats.arenas.") && v.ends_with(b".dss") => {
true
}
_ => false,
}
}
@ -321,7 +323,8 @@ impl<T: MibArg> Access<&'static str> for MibStr<T> {
fn update(&self, value: &'static str) -> Result<&'static str> {
// this is safe because the only safe way to construct a `MibStr` is by
// validating that the key refers to a byte-string value
let s = unsafe { raw::update_str_mib(self.0.as_ref(), value.as_bytes())? };
let s =
unsafe { raw::update_str_mib(self.0.as_ref(), value.as_bytes())? };
Ok(str::from_utf8(s).unwrap())
}
}
@ -431,10 +434,22 @@ mod tests {
}
pub trait MibArg:
Copy + Clone + PartialEq + Default + fmt::Debug + AsRef<[usize]> + AsMut<[usize]>
Copy
+ Clone
+ PartialEq
+ Default
+ fmt::Debug
+ AsRef<[usize]>
+ AsMut<[usize]>
{
}
impl<T> MibArg for T where
T: Copy + Clone + PartialEq + Default + fmt::Debug + AsRef<[usize]> + AsMut<[usize]>
T: Copy
+ Clone
+ PartialEq
+ Default
+ fmt::Debug
+ AsRef<[usize]>
+ AsMut<[usize]>
{
}

View File

@ -70,7 +70,7 @@
//! }
//! }
//! ```
#![deny(missing_docs)]
#![deny(missing_docs, intra_doc_link_resolution_failure)]
#![cfg_attr(not(feature = "use_std"), no_std)]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::stutter))]
#![feature(coerce_unsized)]

View File

@ -273,7 +273,10 @@ pub fn write_str_mib(mib: &[usize], value: &'static [u8]) -> Result<()> {
/// If the pointer is valid but it does not point to a null-terminated string,
/// looking for `\0` will read garbage and might end up reading out-of-bounds,
/// which is undefined behavior.
pub unsafe fn update_str_mib(mib: &[usize], value: &'static [u8]) -> Result<&'static [u8]> {
pub unsafe fn update_str_mib(
mib: &[usize],
value: &'static [u8],
) -> Result<&'static [u8]> {
let ptr: *const c_char = update_mib(mib, value.as_ptr() as *const c_char)?;
ptr2str(ptr)
}
@ -340,7 +343,10 @@ pub fn write_str(name: &[u8], value: &'static [u8]) -> Result<()> {
/// If the pointer is valid but it does not point to a null-terminated string,
/// looking for `\0` will read garbage and might end up reading out-of-bounds,
/// which is undefined behavior.
pub unsafe fn update_str(name: &[u8], value: &'static [u8]) -> Result<&'static [u8]> {
pub unsafe fn update_str(
name: &[u8],
value: &'static [u8],
) -> Result<&'static [u8]> {
let ptr: *const c_char = update(name, value.as_ptr() as *const c_char)?;
ptr2str(ptr)
}

View File

@ -68,7 +68,9 @@ where
}
let buf = CStr::from_ptr(buf);
match panic::catch_unwind(AssertUnwindSafe(|| state.writer.write_all(buf.to_bytes()))) {
match panic::catch_unwind(AssertUnwindSafe(|| {
state.writer.write_all(buf.to_bytes())
})) {
Ok(Ok(_)) => {}
Ok(Err(e)) => state.error = Err(e),
Err(e) => state.panic = Err(e),