Skip to content

Commit

Permalink
Fixes #32 (#49)
Browse files Browse the repository at this point in the history
Default-construct `xwhat` and filter out empty ones in order to allow more Valgrind output.
  • Loading branch information
vhqtvn authored Oct 28, 2021
1 parent 625dafa commit 8de40ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/valgrind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,23 @@ where
listener
.read_to_end(&mut output)
.map_err(|_| Error::SocketConnection)?;
let xml: xml::Output =
serde_xml_rs::from_reader(&*output).map_err(|e| Error::MalformedOutput(e, output))?;
let xml: xml::Output = serde_xml_rs::from_reader(&*output)
.map(|output_: xml::Output| {
let mut output = output_;
if let Some(err) = output.errors {
let new_err: Vec<xml::Error> = err
.into_iter()
.filter(|e| e.resources.bytes > 0 || e.resources.blocks > 0)
.collect();
if new_err.len() > 0 {
output.errors = Some(new_err)
} else {
output.errors = None
}
}
output
})
.map_err(|e| Error::MalformedOutput(e, output))?;
Ok(xml)
});

Expand Down
10 changes: 10 additions & 0 deletions src/valgrind/xml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct Error {
#[serde(deserialize_with = "deserialize_hex")]
unique: u64,
pub kind: Kind,
#[serde(default)]
#[serde(rename = "xwhat")]
pub resources: Resources,
#[serde(rename = "stack")]
Expand Down Expand Up @@ -152,6 +153,15 @@ fn deserialize_hex<'de, D: Deserializer<'de>>(deserializer: D) -> Result<u64, D:
deserializer.deserialize_str(HexVisitor)
}

impl Default for Resources {
fn default() -> Self {
Resources {
bytes: 0,
blocks: 0,
}
}
}

/// A visitor for parsing a `u64` in the format `0xDEADBEEF`.
struct HexVisitor;
impl<'de> Visitor<'de> for HexVisitor {
Expand Down

0 comments on commit 8de40ea

Please sign in to comment.