From 89bb4220290d948161eb40f5ffa3fbd0933eea8c Mon Sep 17 00:00:00 2001 From: Bill Fraser Date: Thu, 19 Jan 2017 21:34:00 -0800 Subject: [PATCH] don't include NUL bytes at the end of the vendor, brand, and codename strings --- src/lib.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4f728dc..b8a43bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -234,13 +234,22 @@ pub fn identify() -> Result { Err(error()) } else { Ok(CpuInfo { - vendor: String::from_utf8(data.vendor_str.iter().map(|&x| x as u8).collect()) + vendor: String::from_utf8(data.vendor_str.iter() + .take_while(|&&x| x != 0) + .map(|&x| x as u8) + .collect()) .ok() .expect("Invalid vendor string"), - brand: String::from_utf8(data.brand_str.iter().map(|&x| x as u8).collect()) + brand: String::from_utf8(data.brand_str.iter() + .take_while(|&&x| x != 0) + .map(|&x| x as u8) + .collect()) .ok() .expect("Invalid brand string"), - codename: String::from_utf8(data.cpu_codename.iter().map(|&x| x as u8).collect()) + codename: String::from_utf8(data.cpu_codename.iter() + .take_while(|&&x| x != 0) + .map(|&x| x as u8) + .collect()) .ok() .expect("Invalid codename string"), num_cores: data.num_cores,