Skip to content

Commit a102825

Browse files
fix: Cppcheck issues (#5217)
I asked Cursor to run Cppcheck and make fixes to the first 10 items it redeems critical, that sort of a test if I can scale this up. I have reviewed the fixes with Shaun Roe (who knows Cppcheck really well). Co-authored-by: Andreas Stefl <487211+andiwand@users.noreply.github.com>
1 parent fa687cd commit a102825

9 files changed

Lines changed: 40 additions & 48 deletions

File tree

Core/include/Acts/Utilities/Grid.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ class Grid final : public IGrid {
267267

268268
/// @copydoc Acts::IGrid::atLocalBinsAny
269269
std::any atLocalBinsAny(AnyIndexType indices) const override {
270-
const_reference cref = atLocalBins(toIndexType(indices));
271-
return &cref;
270+
return &atLocalBins(toIndexType(indices));
272271
}
273272

274273
/// @brief access value stored in bin with given local bin numbers
@@ -285,8 +284,7 @@ class Grid final : public IGrid {
285284

286285
/// @copydoc Acts::IGrid::atLocalBinsAny
287286
std::any atLocalBinsAny(AnyIndexType indices) override {
288-
reference ref = atLocalBins(toIndexType(indices));
289-
return &ref;
287+
return &atLocalBins(toIndexType(indices));
290288
}
291289

292290
/// @brief get global bin indices for closest points on grid

Core/include/Acts/Utilities/detail/grid_helper.hpp

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ struct grid_helper {
533533
const std::array<std::size_t, sizeof...(Axes)>& localIndices,
534534
const std::tuple<Axes...>& axes) {
535535
std::array<double, sizeof...(Axes)> center{};
536-
constexpr std::size_t MAX = sizeof...(Axes) - 1;
537-
grid_helper_impl<MAX>::getBinCenter(center, localIndices, axes);
536+
grid_helper_impl<sizeof...(Axes) - 1>::getBinCenter(center, localIndices,
537+
axes);
538538

539539
return center;
540540
}
@@ -553,11 +553,11 @@ struct grid_helper {
553553
static std::size_t getGlobalBin(
554554
const std::array<std::size_t, sizeof...(Axes)>& localBins,
555555
const std::tuple<Axes...>& axes) {
556-
constexpr std::size_t MAX = sizeof...(Axes) - 1;
557556
std::size_t area = 1;
558557
std::size_t bin = 0;
559558

560-
grid_helper_impl<MAX>::getGlobalBin(localBins, axes, bin, area);
559+
grid_helper_impl<sizeof...(Axes) - 1>::getGlobalBin(localBins, axes, bin,
560+
area);
561561

562562
return bin;
563563
}
@@ -579,10 +579,10 @@ struct grid_helper {
579579
template <class Point, class... Axes>
580580
static std::array<std::size_t, sizeof...(Axes)> getLocalBinIndices(
581581
const Point& point, const std::tuple<Axes...>& axes) {
582-
constexpr std::size_t MAX = sizeof...(Axes) - 1;
583582
std::array<std::size_t, sizeof...(Axes)> indices{};
584583

585-
grid_helper_impl<MAX>::getLocalBinIndices(point, axes, indices);
584+
grid_helper_impl<sizeof...(Axes) - 1>::getLocalBinIndices(point, axes,
585+
indices);
586586

587587
return indices;
588588
}
@@ -600,11 +600,11 @@ struct grid_helper {
600600
template <class... Axes>
601601
static std::array<std::size_t, sizeof...(Axes)> getLocalBinIndices(
602602
std::size_t bin, const std::tuple<Axes...>& axes) {
603-
constexpr std::size_t MAX = sizeof...(Axes) - 1;
604603
std::size_t area = 1;
605604
std::array<std::size_t, sizeof...(Axes)> indices{};
606605

607-
grid_helper_impl<MAX>::getLocalBinIndices(bin, axes, area, indices);
606+
grid_helper_impl<sizeof...(Axes) - 1>::getLocalBinIndices(bin, axes, area,
607+
indices);
608608

609609
return indices;
610610
}
@@ -623,8 +623,8 @@ struct grid_helper {
623623
const std::array<std::size_t, sizeof...(Axes)>& localIndices,
624624
const std::tuple<Axes...>& axes) {
625625
std::array<double, sizeof...(Axes)> llEdge{};
626-
constexpr std::size_t MAX = sizeof...(Axes) - 1;
627-
grid_helper_impl<MAX>::getLowerLeftBinEdge(llEdge, localIndices, axes);
626+
grid_helper_impl<sizeof...(Axes) - 1>::getLowerLeftBinEdge(
627+
llEdge, localIndices, axes);
628628

629629
return llEdge;
630630
}
@@ -646,9 +646,9 @@ struct grid_helper {
646646
static std::array<std::size_t, sizeof...(Axes)> getLowerLeftBinIndices(
647647
const std::array<std::size_t, sizeof...(Axes)>& localIndices,
648648
const std::tuple<Axes...>& axes) {
649-
constexpr std::size_t MAX = sizeof...(Axes) - 1;
650649
auto llIndices = localIndices;
651-
grid_helper_impl<MAX>::getLowerLeftBinIndices(llIndices, axes);
650+
grid_helper_impl<sizeof...(Axes) - 1>::getLowerLeftBinIndices(llIndices,
651+
axes);
652652

653653
return llIndices;
654654
}
@@ -697,8 +697,8 @@ struct grid_helper {
697697
const std::array<std::size_t, sizeof...(Axes)>& localIndices,
698698
const std::tuple<Axes...>& axes) {
699699
std::array<double, sizeof...(Axes)> urEdge{};
700-
constexpr std::size_t MAX = sizeof...(Axes) - 1;
701-
grid_helper_impl<MAX>::getUpperRightBinEdge(urEdge, localIndices, axes);
700+
grid_helper_impl<sizeof...(Axes) - 1>::getUpperRightBinEdge(
701+
urEdge, localIndices, axes);
702702

703703
return urEdge;
704704
}
@@ -720,9 +720,9 @@ struct grid_helper {
720720
static std::array<std::size_t, sizeof...(Axes)> getUpperRightBinIndices(
721721
const std::array<std::size_t, sizeof...(Axes)>& localIndices,
722722
const std::tuple<Axes...>& axes) {
723-
constexpr std::size_t MAX = sizeof...(Axes) - 1;
724723
auto urIndices = localIndices;
725-
grid_helper_impl<MAX>::getUpperRightBinIndices(urIndices, axes);
724+
grid_helper_impl<sizeof...(Axes) - 1>::getUpperRightBinIndices(urIndices,
725+
axes);
726726

727727
return urIndices;
728728
}
@@ -791,13 +791,11 @@ struct grid_helper {
791791
const std::array<std::size_t, sizeof...(Axes)>& localIndices,
792792
std::pair<std::size_t, std::size_t> sizes,
793793
const std::tuple<Axes...>& axes) {
794-
constexpr std::size_t MAX = sizeof...(Axes) - 1;
795-
796794
// length N array which contains local neighbors based on size par
797795
std::array<NeighborHoodIndices, sizeof...(Axes)> neighborIndices{};
798796
// get local bin indices for neighboring bins
799-
grid_helper_impl<MAX>::neighborHoodIndices(localIndices, sizes, axes,
800-
neighborIndices);
797+
grid_helper_impl<sizeof...(Axes) - 1>::neighborHoodIndices(
798+
localIndices, sizes, axes, neighborIndices);
801799

802800
// Query the number of bins
803801
std::array<std::size_t, sizeof...(Axes)> nBinsArray = getNBins(axes);
@@ -840,13 +838,11 @@ struct grid_helper {
840838
const std::array<std::size_t, sizeof...(Axes)>& localIndices,
841839
std::array<std::pair<int, int>, sizeof...(Axes)>& sizes,
842840
const std::tuple<Axes...>& axes) {
843-
constexpr std::size_t MAX = sizeof...(Axes) - 1;
844-
845841
// length N array which contains local neighbors based on size par
846842
std::array<NeighborHoodIndices, sizeof...(Axes)> neighborIndices{};
847843
// get local bin indices for neighboring bins
848-
grid_helper_impl<MAX>::neighborHoodIndices(localIndices, sizes, axes,
849-
neighborIndices);
844+
grid_helper_impl<sizeof...(Axes) - 1>::neighborHoodIndices(
845+
localIndices, sizes, axes, neighborIndices);
850846

851847
// Query the number of bins
852848
std::array<std::size_t, sizeof...(Axes)> nBinsArray = getNBins(axes);
@@ -863,13 +859,11 @@ struct grid_helper {
863859
template <class... Axes>
864860
static std::set<std::size_t> exteriorBinIndices(
865861
const std::tuple<Axes...>& axes) {
866-
constexpr std::size_t MAX = sizeof...(Axes) - 1;
867-
868862
std::array<std::size_t, sizeof...(Axes)> idx{};
869863
std::array<bool, sizeof...(Axes)> isExterior{};
870864
std::set<std::size_t> combinations;
871-
grid_helper_impl<MAX>::exteriorBinIndices(idx, isExterior, combinations,
872-
axes);
865+
grid_helper_impl<sizeof...(Axes) - 1>::exteriorBinIndices(
866+
idx, isExterior, combinations, axes);
873867

874868
return combinations;
875869
}

Core/src/Definitions/ParticleIdHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ int charge3(const DecodedPID& p) {
654654
int signmult = 1;
655655
int result = 0;
656656
bool classified = false;
657-
if (!classified && isMeson(p)) {
657+
if (isMeson(p)) {
658658
classified = true;
659659
nq = 2;
660660
if ((*(p.second.rbegin() + 2)) == 2 || (*(p.second.rbegin() + 2)) == 4) {

Core/src/Surfaces/AnnulusBounds.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ Vector2 AnnulusBounds::closestPoint(const Vector2& lposition,
372372
double currentDist =
373373
squaredNorm(lpositionModulePC - currentClosest, metricModulePC);
374374
if (currentDist < minDist) {
375-
minDist = currentDist;
376375
closest = m_rotationStripPC.inverse() * modulePCToStripPC(currentClosest);
377376
}
378377
}

Examples/Framework/include/ActsExamples/Framework/IAlgorithm.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ class IAlgorithm : public SequenceElement {
3030
/// @level The logging level for this algorithm
3131
/// @deprecated Use the constructor with a logger instead
3232
[[deprecated("Use the constructor with a logger instead")]]
33-
explicit IAlgorithm(std::string name, Acts::Logging::Level level);
33+
explicit IAlgorithm(const std::string& name, Acts::Logging::Level level);
3434

3535
/// Constructor
3636
///
3737
/// @name The algorithm name
3838
/// @logger The logger for this algorithm
39-
explicit IAlgorithm(std::string name,
39+
explicit IAlgorithm(const std::string& name,
4040
std::unique_ptr<const Acts::Logger> logger = nullptr);
4141

4242
/// The algorithm name.

Examples/Framework/src/Framework/IAlgorithm.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
namespace ActsExamples {
1616

17-
IAlgorithm::IAlgorithm(std::string name, Acts::Logging::Level level)
18-
: IAlgorithm(std::move(name), Acts::getDefaultLogger(name, level)) {}
17+
IAlgorithm::IAlgorithm(const std::string& name, Acts::Logging::Level level)
18+
: IAlgorithm(name, Acts::getDefaultLogger(name, level)) {}
1919

20-
IAlgorithm::IAlgorithm(std::string name,
20+
IAlgorithm::IAlgorithm(const std::string& name,
2121
std::unique_ptr<const Acts::Logger> logger)
22-
: m_name(std::move(name)),
22+
: m_name(name),
2323
m_logger(logger != nullptr
2424
? std::move(logger)
2525
: Acts::getDefaultLogger(name, Acts::Logging::INFO)) {}

Examples/Framework/src/Framework/WhiteBoard.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,11 @@ void WhiteBoard::addHolder(const std::string &name,
124124
: "unknown")
125125
<< "'");
126126

127-
if (success) {
128-
// deal with aliases
129-
auto range = m_objectAliases.equal_range(name);
130-
for (auto it = range.first; it != range.second; ++it) {
131-
m_store[it->second] = storeVal;
132-
ACTS_VERBOSE("Added alias object '" << it->second << "'");
133-
}
127+
// deal with aliases
128+
auto range = m_objectAliases.equal_range(name);
129+
for (auto it = range.first; it != range.second; ++it) {
130+
m_store[it->second] = storeVal;
131+
ACTS_VERBOSE("Added alias object '" << it->second << "'");
134132
}
135133
}
136134

Examples/Scripts/TrackingPerformance/CommonUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
/// @param color the color
2626
template <typename hist_t>
2727
void setHistStyle(hist_t* hist, short color = 1) {
28+
if (hist == nullptr) {
29+
return;
30+
}
2831
hist->GetXaxis()->SetTitleSize(0.04);
2932
hist->GetYaxis()->SetTitleSize(0.04);
3033
hist->GetXaxis()->SetLabelSize(0.04);

Plugins/ActSVG/include/ActsPlugins/ActSVG/SvgUtils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct Style {
8484
fnt._size = fontSize;
8585
fnt._fc._rgb = fontColor;
8686

87-
return std::tie(fll, str, fnt);
87+
return {fll, str, fnt};
8888
}
8989
};
9090

0 commit comments

Comments
 (0)