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

[GEOMETRY] Fixes needed for UBSAN #30232

Merged
merged 3 commits into from Jun 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 9 additions & 7 deletions Geometry/EcalAlgo/test/EcalPreshowerParameterDump.cc
Expand Up @@ -17,6 +17,7 @@

#include <iomanip>
#include <iostream>
#include <sstream> // for ostringstream

typedef EZArrayFL<GlobalPoint> CornersVec;

Expand All @@ -42,13 +43,14 @@ EcalPreshowerCellParameterDump::EcalPreshowerCellParameterDump(const edm::Parame

if (debug_) {
edm::Service<TFileService> fs;
for (int iz = 0; iz < 2; ++iz) {
int zside = 2 * iz - 1;
for (int lay = 1; lay <= 2; ++lay) {
char name[20], title[40];
sprintf(name, "hist%d%d", iz, lay);
sprintf(title, "y vs. x (zside = %d,layer = %d)", zside, lay);
hist_.emplace_back(fs->make<TH2D>(name, title, 5000, -125.0, 125.0, 5000, -125.0, 125.0));
for (short iz = 0; iz < 2; ++iz) {
short zside = 2 * iz - 1;
for (short lay = 1; lay <= 2; ++lay) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@smuzaffar - sprintf is not thread safe - it should be replaced with std::ostringstream:

#include <sstream> // for ostringstream

std::ostringstream out;

out << ”hist” << iz << lay;

Copy link
Contributor

Choose a reason for hiding this comment

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

Or even better to std::format when we switch to C++20:

std::string message = std::format("The answer is {}.", 42);

https://en.cppreference.com/w/cpp/utility/format

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 , used ostringstream

std::ostringstream name, title;
name << "hist" << iz << lay;
title << "y vs. x (zside = " << zside << ",layer = " << lay << ")";
hist_.emplace_back(
fs->make<TH2D>(name.str().c_str(), title.str().c_str(), 5000, -125.0, 125.0, 5000, -125.0, 125.0));
}
}
}
Expand Down