Correct the position and record count of broken canary

This commit is contained in:
Xidorn Quan 2017-10-13 15:20:17 +11:00
parent b547e96b44
commit cb2772b46c

View file

@ -60,17 +60,19 @@ impl<K: Hash + Eq, V, S: BuildHasher> DiagnosticHashMap<K, V, S>
fn verify(&self) { fn verify(&self) {
let mut position = 0; let mut position = 0;
let mut bad_canary: Option<(usize, *const usize)> = None; let mut count = 0;
let mut bad_canary = None;
for (_,v) in self.map.iter() { for (_,v) in self.map.iter() {
let canary_ref = &v.0; let canary_ref = &v.0;
if *canary_ref == CANARY {
position += 1; position += 1;
if *canary_ref == CANARY {
continue; continue;
} }
bad_canary = Some((*canary_ref, canary_ref)); count += 1;
bad_canary = Some((*canary_ref, canary_ref, position));
} }
if let Some(c) = bad_canary { if let Some(c) = bad_canary {
self.report_corruption(c.0, c.1, position); self.report_corruption(c.0, c.1, c.2, count);
} }
} }
@ -158,7 +160,8 @@ impl<K: Hash + Eq, V, S: BuildHasher> DiagnosticHashMap<K, V, S>
&self, &self,
canary: usize, canary: usize,
canary_addr: *const usize, canary_addr: *const usize,
position: usize position: usize,
count: usize,
) { ) {
use ::std::ffi::CString; use ::std::ffi::CString;
let key = b"HashMapJournal\0"; let key = b"HashMapJournal\0";
@ -170,11 +173,13 @@ impl<K: Hash + Eq, V, S: BuildHasher> DiagnosticHashMap<K, V, S>
); );
} }
panic!( panic!(
"HashMap Corruption (sz={}, cap={}, pairsz={}, cnry={:#x}, pos={}, base_addr={:?}, cnry_addr={:?}, jrnl_len={})", concat!("HashMap Corruption (sz={}, cap={}, pairsz={}, cnry={:#x}, count={}, ",
"last_pos={}, base_addr={:?}, cnry_addr={:?}, jrnl_len={})"),
self.map.len(), self.map.len(),
self.map.raw_capacity(), self.map.raw_capacity(),
::std::mem::size_of::<(K, (usize, V))>(), ::std::mem::size_of::<(K, (usize, V))>(),
canary, canary,
count,
position, position,
self.map.raw_buffer(), self.map.raw_buffer(),
canary_addr, canary_addr,