Skip to content

Commit

Permalink
Merge pull request #36802 from Dr15Jones/ubsanGeneratorInterfaceCore
Browse files Browse the repository at this point in the history
Fix calling methods on nullptr in Concurrent*Filter modules
  • Loading branch information
cmsbuild authored Jan 26, 2022
2 parents ec200b2 + a4e0ad9 commit 70c9065
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions GeneratorInterface/Core/interface/ConcurrentGeneratorFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,16 @@ namespace edm {
Service<RandomNumberGenerator> rng;
auto enginePtr = rng->cloneEngine(lumi.index());
cache->hadronizer_.setRandomEngine(enginePtr.get());
cache->decayer_->setRandomEngine(enginePtr.get());
if (cache->decayer_) {
cache->decayer_->setRandomEngine(enginePtr.get());
}

auto unsetH = [](HAD* h) { h->setRandomEngine(nullptr); };
auto unsetD = [](DEC* d) { d->setRandomEngine(nullptr); };
auto unsetD = [](DEC* d) {
if (d) {
d->setRandomEngine(nullptr);
}
};

std::unique_ptr<HAD, decltype(unsetH)> randomEngineSentry(&cache->hadronizer_, unsetH);
std::unique_ptr<DEC, decltype(unsetD)> randomEngineSentryDecay(cache->decayer_.get(), unsetD);
Expand Down
10 changes: 8 additions & 2 deletions GeneratorInterface/Core/interface/ConcurrentHadronizerFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,16 @@ namespace edm {
Service<RandomNumberGenerator> rng;
auto enginePtr = rng->cloneEngine(lumi.index());
cache->hadronizer_.setRandomEngine(enginePtr.get());
cache->decayer_->setRandomEngine(enginePtr.get());
if (cache->decayer_) {
cache->decayer_->setRandomEngine(enginePtr.get());
}

auto unsetH = [](HAD* h) { h->setRandomEngine(nullptr); };
auto unsetD = [](DEC* d) { d->setRandomEngine(nullptr); };
auto unsetD = [](DEC* d) {
if (d) {
d->setRandomEngine(nullptr);
}
};

std::unique_ptr<HAD, decltype(unsetH)> randomEngineSentry(&cache->hadronizer_, unsetH);
std::unique_ptr<DEC, decltype(unsetD)> randomEngineSentryDecay(cache->decayer_.get(), unsetD);
Expand Down

0 comments on commit 70c9065

Please sign in to comment.