Skip to content

Commit

Permalink
Merge pull request #47074 from smuzaffar/ubsan-HepMCProduct-fix1
Browse files Browse the repository at this point in the history
[UBSAN]Properly initialize datamembers for move operator
  • Loading branch information
cmsbuild authored Jan 10, 2025
2 parents c09d976 + d16cf31 commit 73cb482
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions SimDataFormats/GeneratorProducts/src/HepMCProduct.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ HepMCProduct::HepMCProduct(HepMCProduct const& other) : evt_(nullptr) {
// swap
void HepMCProduct::swap(HepMCProduct& other) {
std::swap(evt_, other.evt_);
isVtxGenApplied_ = other.isVtxGenApplied_;
isVtxBoostApplied_ = other.isVtxBoostApplied_;
isPBoostApplied_ = other.isPBoostApplied_;
std::swap(isVtxGenApplied_, other.isVtxGenApplied_);
std::swap(isVtxBoostApplied_, other.isVtxBoostApplied_);
std::swap(isPBoostApplied_, other.isPBoostApplied_);
}

// assignment: use copy/swap idiom for exception safety.
Expand All @@ -143,7 +143,10 @@ HepMCProduct& HepMCProduct::operator=(HepMCProduct const& other) {
}

// move, needed explicitly as we have raw pointer...
HepMCProduct::HepMCProduct(HepMCProduct&& other) : evt_(nullptr) { swap(other); }
HepMCProduct::HepMCProduct(HepMCProduct&& other)
: evt_(nullptr), isVtxGenApplied_(false), isVtxBoostApplied_(false), isPBoostApplied_(false) {
swap(other);
}
HepMCProduct& HepMCProduct::operator=(HepMCProduct&& other) {
swap(other);
return *this;
Expand Down

0 comments on commit 73cb482

Please sign in to comment.