Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rare Undefined Behavior in PixelThresholdClusterizer #35275

Merged
merged 3 commits into from
Sep 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ void PixelThresholdClusterizer::clusterizeDetUnitT(const T& input,

// Copy PixelDigis to the buffer array; select the seed pixels
// on the way, and store them in theSeeds.
copy_to_buffer(begin, end);
if (end > begin)
copy_to_buffer(begin, end);

assert(output.empty());
// Loop over all seeds. TO DO: wouldn't using iterators be faster?
Expand Down Expand Up @@ -222,6 +223,13 @@ void PixelThresholdClusterizer::copy_to_buffer(DigiIterator begin, DigiIterator
// std::cout << (doMissCalibrate ? "VI from db" : "VI linear") << std::endl;
}
#endif

//If called with empty/invalid DetSet, warn the user
if (end <= begin) {
edm::LogWarning("PixelThresholdClusterizer") << " copy_to_buffer called with empty or invalid range" << std::endl;
return;
}

int electron[end - begin]; // pixel charge in electrons
memset(electron, 0, (end - begin) * sizeof(int));

Expand Down