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

[LTO_X - Alignment & Calibration] Solve -Wstrict-overflow compiler warnings #38649

Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Alignment/OfflineValidation/plugins/OverlapValidation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void OverlapValidation::analyzeTrajectory(const Trajectory& trajectory,
++overlapCounts_[1];
if ((layer != -1) && (acceptLayer[subDet])) {
for (vector<TrajectoryMeasurement>::const_iterator itmCompare = itm - 1;
itmCompare >= measurements.begin() && itmCompare > itm - 4;
(itmCompare >= measurements.begin()) && ((itmCompare + 4) > itm);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue comparing an iterator to be larger than or equal with begin() does not make much sense as in principle it is always true because

The begin iterator is not decrementable and the behavior is undefined if --container.begin() is evaluated.

https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but itm-1 has a similar issue when itm is equal to measurements.begin(), no? or is that somehow ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but itm-1 has a similar issue when itm is equal to measurements.begin(), no?

Right (didn't look that far), already the itm-1 seems to be potentially undefined behavior.

How about rewriting the loop e.g. along

for (int offset = 1, end=std::min(3, std::distance(measurements.begin(), itm)); offset <= end; ++offset) {
  auto itmCompare = std::prev(itm, offset);
  ...
}

Then, for

  • itm == begin() the loop body would not be run
  • itm == begin()+1 the loop body would be run with itmCompare = itm-1
  • itm == begin()+2 the loop body would be run with itmCompare = itm-1 and itm-2
  • itm >= begin()+3 the loop body would be run with itmCompare = itm-1, itm-2, and itm-3

(I'm sure there are even better ways to write the loop)

--itmCompare) {
DetId compareId = itmCompare->recHit()->geographicalId();

Expand Down
2 changes: 1 addition & 1 deletion Alignment/TrackerAlignment/plugins/TkAlCaOverlapTagger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void TkAlCaOverlapTagger::produce(edm::Event& iEvent, const edm::EventSetup& iSe

if ((previousTM != nullptr) && (layer != -1)) {
for (std::vector<TrajectoryMeasurement>::const_iterator itmCompare = itTrajMeas - 1;
itmCompare >= tmColl.begin() && itmCompare > itTrajMeas - 4;
(itmCompare >= tmColl.begin()) && ((itmCompare + 4) > itTrajMeas);
--itmCompare) {
DetId compareId = itmCompare->recHit()->geographicalId();
if (subDet != compareId.subdetId() || layer != layerFromId(compareId, tTopo))
Expand Down
2 changes: 1 addition & 1 deletion Calibration/Tools/src/HouseholderDecomposition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ void HouseholderDecomposition::solve(std::vector<float>& y) {

for (i = Nchannels - 2; i >= 0; i--) {
z[i] = energyVectorProc[i];
for (j = i + 1; j < Nchannels; j++) {
for (j = i + 1; j - Nchannels < 0; j++) {
z[i] -= eventMatrixProc[i][j] * z[j];
}
z[i] /= alpha[i];
Expand Down