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 UB in DetectorIDTest.cxx #1436

Merged
merged 1 commit into from
Sep 5, 2024
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
33 changes: 17 additions & 16 deletions DetDescr/test/DetectorIDTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ TEST_CASE("DetectorID", "[DetDescr][functionality]") {
REQUIRE_THROWS(EcalID(0x829018));
REQUIRE_NOTHROW(EcalID(did_ecal));
REQUIRE_NOTHROW(EcalID(did_ecal.raw()));

EcalID eid(50, 15, 500); // choose big values to check collisions
// choose big values to check collisions
EcalID eid(50, 15, 500);

REQUIRE(eid.raw() == 0x1464f1f4);

Expand Down Expand Up @@ -89,8 +89,8 @@ TEST_CASE("DetectorID", "[DetDescr][functionality]") {
REQUIRE_NOTHROW(HcalID(did_hcal));
REQUIRE_NOTHROW(HcalID(did_hcal.raw()));

HcalID hid(HcalID::LEFT, 250,
245); // choose big values to check collisions
// choose big values to check collisions
HcalID hid(HcalID::LEFT, 250, 245);

REQUIRE(hid.raw() == 0x1813e8f5);

Expand Down Expand Up @@ -132,10 +132,10 @@ TEST_CASE("DetectorID", "[DetDescr][functionality]") {
REQUIRE_NOTHROW(TrackerID(did_tk));
REQUIRE_NOTHROW(TrackerID(did_tk.raw()));

TrackerID tid(SD_TRACKER_TAGGER, 250,
30); // choose big values to check collisions
TrackerID tid2(SD_TRACKER_RECOIL, 220,
17); // choose big values to check collisions
// choose big values to check collisions
TrackerID tid(SD_TRACKER_TAGGER, 250, 30);
// choose big values to check collisions
TrackerID tid2(SD_TRACKER_RECOIL, 220, 17);

REQUIRE(tid.raw() == 0x4001efa);
REQUIRE(tid2.raw() == 0x100011dc);
Expand Down Expand Up @@ -173,7 +173,8 @@ TEST_CASE("DetectorID", "[DetDescr][functionality]") {
REQUIRE_NOTHROW(TrigScintID(did_ts));
REQUIRE_NOTHROW(TrigScintID(did_ts.raw()));

TrigScintID ts_id(250, 245); // choose big values to check collisions
// choose big values to check collisions
TrigScintID ts_id(250, 245);

CHECK(ts_id.raw() == 0x800faf5);

Expand Down Expand Up @@ -209,26 +210,26 @@ TEST_CASE("DetectorID", "[DetDescr][functionality]") {
REQUIRE_NOTHROW(SimSpecialID(did_ss));
REQUIRE_NOTHROW(SimSpecialID(did_ss.raw()));

SimSpecialID ssid = SimSpecialID::ScoringPlaneID(
3210); // choose big values to check collisions
SimSpecialID ssid2(SimSpecialID::SimSpecialType(9), 0xFEDCB);
// choose big values to check collisions
SimSpecialID ssid = SimSpecialID::ScoringPlaneID(3210);
SimSpecialID ssid2(SimSpecialID::SimSpecialType(1), 0xFEDCB);

CHECK(ssid.raw() == 0x1c400c8a);
CHECK(ssid2.raw() == 0x1e4fedcb);
CHECK(ssid2.raw() == 0x1c4fedcb);

REQUIRE(ssid.getSubtype() == SimSpecialID::SCORING_PLANE);
REQUIRE(ssid2.getSubtype() == 9);
REQUIRE(ssid2.getSubtype() == 1);

REQUIRE(ssid.plane() == 3210);
REQUIRE(ssid2.plane() == -1);
REQUIRE(ssid2.plane() == 3531);
REQUIRE(ssid.subtypePayload() == 3210);
REQUIRE(ssid2.subtypePayload() == 0xfedcb);

std::stringstream ss;
ss << ssid << ssid2;

REQUIRE(ss.str() ==
"SimSpecial(ScoringPlane 3210)SimSpecial(Type 9,1043915)");
"SimSpecial(ScoringPlane 3210)SimSpecial(ScoringPlane 3531)");

DetectorIDInterpreter dii(ssid);

Expand Down
Loading