Index: chrome/browser/safe_browsing/prefix_set.cc |
diff --git a/chrome/browser/safe_browsing/prefix_set.cc b/chrome/browser/safe_browsing/prefix_set.cc |
index d9a889745c43a2c82bf4a27daaf7b3c75aa89072..4191427e43667b41026ea05ce9e80e4694d3167c 100644 |
--- a/chrome/browser/safe_browsing/prefix_set.cc |
+++ b/chrome/browser/safe_browsing/prefix_set.cc |
@@ -165,6 +165,32 @@ void PrefixSet::GetPrefixes(std::vector<SBPrefix>* prefixes) const { |
} |
} |
+// NOTE(shess): For debugging potential memory corruption. I wanted |
+// to test that the output of GetPrefixes() matched the checksum over |
+// the unique elements in the input to the constructor, but the buffer |
+// for GetPrefixes() to write to could itself be corrupted. That |
+// would make it look like GetPrefixes() itself was broken. At that |
+// point my head exploded, so I wrote this. |
+SBPrefix PrefixSet::GetPrefixesChecksum() const { |
+ SBPrefix checksum = 0; |
+ |
+ for (size_t ii = 0; ii < index_.size(); ++ii) { |
+ // The deltas for this |index_| entry run to the next index entry, |
+ // or the end of the deltas. |
+ const size_t deltas_end = |
+ (ii + 1 < index_.size()) ? index_[ii + 1].second : deltas_.size(); |
+ |
+ SBPrefix current = index_[ii].first; |
+ checksum ^= current; |
+ for (size_t di = index_[ii].second; di < deltas_end; ++di) { |
+ current += deltas_[di]; |
+ checksum ^= current; |
+ } |
+ } |
+ |
+ return checksum; |
+} |
+ |
// static |
PrefixSet* PrefixSet::LoadFile(const FilePath& filter_name) { |
int64 size_64; |