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

[SIMULATION] [Clang]Cleanup clang-analyzer warnings #46238

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

smuzaffar
Copy link
Contributor

@cmsbuild
Copy link
Contributor

cmsbuild commented Oct 3, 2024

cms-bot internal usage

@cmsbuild
Copy link
Contributor

cmsbuild commented Oct 3, 2024

@cmsbuild
Copy link
Contributor

cmsbuild commented Oct 3, 2024

A new Pull Request was created by @smuzaffar for master.

It involves the following packages:

  • SimCalorimetry/EcalElectronicsEmulation (simulation)
  • SimG4CMS/HcalTestBeam (simulation)
  • SimG4Core/CustomPhysics (simulation)
  • SimG4Core/Geometry (simulation)
  • SimG4Core/Notification (simulation)
  • SimG4Core/PhysicsLists (simulation)
  • SimG4Core/PrintGeomInfo (simulation)
  • SimGeneral/PileupInformation (simulation)
  • SimTransport/TotemRPProtonTransportParametrization (simulation)

@civanch, @cmsbuild, @kpedro88, @mdhildreth can you please review it and eventually sign? Thanks.
@ReyerBand, @argiro, @bsunanda, @fabiocos, @makortel, @martinamalberti, @rchatter, @rovere, @sameasy, @slomeo, @thomreis, @wang0jin this is something you requested to watch as well.
@antoniovilela, @mandrenguyen, @rappoccio, @sextonkennedy you are the release manager for this.

cms-bot commands are listed here

@@ -87,7 +87,7 @@ G4double CMSSQNeutronAnnih::momDistr(G4double x_in) {

//now interpolate the above points for x_in
G4double result = 9999;
for (int i = 0; i < n_entries; i++) {
for (int i = 1; i < n_entries; i++) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

clang-analyzer was complaining that for i=0, we are trying to access CDF_k[-1] and x[-1. So I started the loop from 1. @cms-sw/simulation-l2 please check if this is correct

Copy link
Contributor

@civanch civanch Oct 3, 2024

Choose a reason for hiding this comment

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

I am not sure what is real range for x_in but I would use following code, which is valid in all cases:

if (x_in <= 0.0) { return 0.0; }
if (x_in >= 1.0) { return CDF_k[n_entries - 1];}
for (int i = 1; i < n_entries; ++i) {
if (x[i] >= x_in) {
return (CDF_k[i] - CDF_k[i - 1]) *(x_in - x[i - 1]) / (x[i] - x[i - 1]) + CDF_k[i - 1];
}
}
return 0.0;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -240,6 +240,8 @@ void CMSG4CheckOverlap::makeReportForOverlaps(std::ofstream& fout,
if (!reg) {
fout << "### NO G4Region found - EXIT"
<< "\n";
if (gdml)
delete gdml;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was a possible memory leak if we fail to get region

Copy link
Contributor

Choose a reason for hiding this comment

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

It is a correct fix. As an alternative, I would remove the check if(!reg), because this should never happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, I have removed the if (!reg){} block

@cmsbuild
Copy link
Contributor

cmsbuild commented Oct 3, 2024

@cmsbuild
Copy link
Contributor

cmsbuild commented Oct 3, 2024

Pull request #46238 was updated. @civanch, @cmsbuild, @kpedro88, @mdhildreth can you please check and sign again.

@smuzaffar
Copy link
Contributor Author

please test

@cmsbuild
Copy link
Contributor

cmsbuild commented Oct 3, 2024

+1

Size: This PR adds an extra 60KB to repository
Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-75a999/41948/summary.html
COMMIT: 71187dc
CMSSW: CMSSW_14_2_X_2024-10-03-1100/el8_amd64_gcc12
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week1/cms-sw/cmssw/46238/41948/install.sh to create a dev area with all the needed externals and cmssw changes.

Comparison Summary

Summary:

@civanch
Copy link
Contributor

civanch commented Oct 4, 2024

+1

@cmsbuild
Copy link
Contributor

cmsbuild commented Oct 4, 2024

This pull request is fully signed and it will be integrated in one of the next master IBs (tests are also fine). This pull request will now be reviewed by the release team before it's merged. @sextonkennedy, @mandrenguyen, @rappoccio, @antoniovilela (and backports should be raised in the release meeting by the corresponding L2)

@mandrenguyen
Copy link
Contributor

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants