Skip to content

Commit

Permalink
Avoid serializing/deserializing uninitialized slots (#651)
Browse files Browse the repository at this point in the history
This avoids errors under ASAN.
  • Loading branch information
rocallahan authored Jul 15, 2024
1 parent 6534adf commit da7c921
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/parallel_hashmap/parallel_hashmap/phmap_dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ bool raw_hash_set<Policy, Hash, Eq, Alloc>::dump(OutputArchive& ar) const {
std::cerr << "Failed to dump ctrl_" << std::endl;
return false;
}
if (!ar.dump(reinterpret_cast<char*>(slots_),
sizeof(slot_type) * capacity_)) {
std::cerr << "Failed to dump slot_" << std::endl;
return false;
for (size_t i = 0; i < capacity_; ++i) {
if (IsFull(ctrl_[i])) {
if (!ar.dump(reinterpret_cast<char*>(slots_) + sizeof(slot_type) * i,
sizeof(slot_type))) {
std::cerr << "Failed to dump slot_ " << i << std::endl;
return false;
}
}
}
return true;
}
Expand Down Expand Up @@ -101,10 +105,15 @@ bool raw_hash_set<Policy, Hash, Eq, Alloc>::load(InputArchive& ar) {
std::cerr << "Failed to load ctrl" << std::endl;
return false;
}
if (!ar.load(reinterpret_cast<char*>(slots_),
sizeof(slot_type) * capacity_)) {
std::cerr << "Failed to load slot" << std::endl;
return false;
for (size_t i = 0; i < capacity_; ++i) {
if (IsFull(ctrl_[i])) {
SanitizerUnpoisonObject(slots_ + i);
if (!ar.load(reinterpret_cast<char*>(slots_) + sizeof(slot_type) * i,
sizeof(slot_type))) {
std::cerr << "Failed to load slot_ " << i << std::endl;
return false;
}
}
}
return true;
}
Expand Down

0 comments on commit da7c921

Please sign in to comment.