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

Cppcheck delta set 54 #38779

Merged
merged 1 commit into from
Feb 10, 2025
Merged
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 Framework/Muon/inc/MantidMuon/PlotAsymmetryByLogValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class MANTID_MUON_DLL PlotAsymmetryByLogValue final : public API::Algorithm {
/// Group detectors
void groupDetectors(API::MatrixWorkspace_sptr &ws, const std::vector<int> &spectraList);
/// Get log value
double getLogValue(API::MatrixWorkspace &ws);
double getLogValue(const API::MatrixWorkspace &ws);
/// Populate output workspace with results
void populateOutputWorkspace(API::MatrixWorkspace_sptr &outWS, int nplots, const std::string &units);
/// get log units
Expand Down
2 changes: 1 addition & 1 deletion Framework/Muon/src/LoadMuonNexus2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void LoadMuonNexus2::exec() {
}

// Need to extract the user-defined output workspace name
Property *ws = getProperty("OutputWorkspace");
const Property *ws = getProperty("OutputWorkspace");
std::string localWSName = ws->value();
// If multiperiod, will need to hold the Instrument & Sample for copying
std::shared_ptr<Instrument> instrument;
Expand Down
12 changes: 6 additions & 6 deletions Framework/Muon/src/PlotAsymmetryByLogValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ const std::string PlotAsymmetryByLogValue::getLogUnits(const std::string &fileNa
ws = std::dynamic_pointer_cast<MatrixWorkspace>(group->getItem(m_red - 1));
}
const Run &run = ws->run();
auto property = run.getLogData(m_logName);
const auto *property = run.getLogData(m_logName);
return property->units();
}

Expand Down Expand Up @@ -449,7 +449,7 @@ void PlotAsymmetryByLogValue::populateOutputWorkspace(MatrixWorkspace_sptr &outW
auto tAxis = std::make_unique<TextAxis>(nplots);
if (nplots == 1) {
size_t i = 0;
for (auto &value : m_logValue) {
for (const auto &value : m_logValue) {
outWS->mutableX(0)[i] = value.second;
outWS->mutableY(0)[i] = m_redY[value.first];
outWS->mutableE(0)[i] = m_redE[value.first];
Expand All @@ -459,7 +459,7 @@ void PlotAsymmetryByLogValue::populateOutputWorkspace(MatrixWorkspace_sptr &outW

} else {
size_t i = 0;
for (auto &value : m_logValue) {
for (const auto &value : m_logValue) {
outWS->mutableX(0)[i] = value.second;
outWS->mutableY(0)[i] = m_diffY[value.first];
outWS->mutableE(0)[i] = m_diffE[value.first];
Expand Down Expand Up @@ -494,7 +494,7 @@ void PlotAsymmetryByLogValue::saveResultsToADS(MatrixWorkspace_sptr &outWS, int

if (nplots == 2) {
size_t i = 0;
for (auto &value : m_logValue) {
for (const auto &value : m_logValue) {
size_t run = value.first;
outWS->mutableX(0)[i] = static_cast<double>(run); // run number
outWS->mutableY(0)[i] = value.second; // log value
Expand All @@ -504,7 +504,7 @@ void PlotAsymmetryByLogValue::saveResultsToADS(MatrixWorkspace_sptr &outWS, int
}
} else {
size_t i = 0;
for (auto &value : m_logValue) {
for (const auto &value : m_logValue) {
size_t run = value.first;
outWS->mutableX(0)[i] = static_cast<double>(run); // run number
outWS->mutableY(0)[i] = value.second; // log value
Expand Down Expand Up @@ -865,7 +865,7 @@ void PlotAsymmetryByLogValue::calcIntAsymmetry(const MatrixWorkspace_sptr &ws_re
* @throw :: std::invalid_argument if the log cannot be converted to a double or
*doesn't exist.
*/
double PlotAsymmetryByLogValue::getLogValue(MatrixWorkspace &ws) {
double PlotAsymmetryByLogValue::getLogValue(const MatrixWorkspace &ws) {
const Run &run = ws.run();
const auto &runROI = run.getTimeROI();

Expand Down
2 changes: 1 addition & 1 deletion Framework/NexusGeometry/src/NexusShapeFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace {
/// Finalise shape
std::unique_ptr<const Geometry::IObject>
createCylinderShape(const std::map<int, std::shared_ptr<Geometry::Surface>> &surfaces, const std::string &algebra,
std::vector<double> &boundingBox, Geometry::detail::ShapeInfo &&shapeInfo) {
const std::vector<double> &boundingBox, Geometry::detail::ShapeInfo &&shapeInfo) {
auto shape = std::make_unique<Geometry::CSGObject>();
shape->setObject(21, algebra);
shape->populate(surfaces);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class MANTID_PARALLEL_DLL EventsListsShmemStorage : public EventsListsShmemManag
public:
EventsListsShmemStorage(const std::string &segmentName, const std::string &elName, size_t size, size_t chunksCnt,
size_t pixelsCount);
virtual ~EventsListsShmemStorage() = default;

void reserve(std::size_t chunkN, std::size_t pixelN, std::size_t size);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ template <typename SvcType, typename SvcPtrType> struct DataServiceExporter {
* @return A shared_ptr to the named object. If the name does not exist it
* sets a KeyError error indicator.
*/
static WeakPtr retrieveOrKeyError(SvcType &self, const std::string &name) {
static WeakPtr retrieveOrKeyError(const SvcType *const self, const std::string &name) {
using namespace Mantid::Kernel;

SvcPtrType item;
try {
item = self.retrieve(name);
item = self->retrieve(name);
} catch (Exception::NotFoundError &) {
// Translate into a Python KeyError
std::string err = "'" + name + "' does not exist.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace PythonInterface {
* @param ptr A * to a raw PyObject
* @returns true if the given object is of type None
*/
inline bool isNone(PyObject *ptr) { return (ptr == Py_None); }
inline bool isNone(const PyObject *ptr) { return (ptr == Py_None); }

/**
* @param obj A const reference to boost python object wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ template <typename ElementType> PyObject *cloneND(const ElementType *carray, con
* @param dims :: The length of the arrays in each dimension
* @return
*/
// cppcheck-suppress constParameterPointer
Copy link
Contributor

Choose a reason for hiding this comment

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

Please could you add a comment here as to why we need a suppression

// Suppressed because one of the cloneND overloads calls
// PyArray_NewFromDescrclasses inside NumpyFunctions::func_PyArray_NewFromDescr, which
// requires the dim parameter to be non-const.
template <> PyObject *cloneND(const std::string *carray, const int ndims, Py_intptr_t *dims) {
boost::python::list pystrs;
const std::string *iter = carray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ NDArrayToVector<DestElementType>::NDArrayToVector(const NDArray &value) : m_arr(
*/
template <typename DestElementType>
typename NDArrayToVector<DestElementType>::TypedVector NDArrayToVector<DestElementType>::operator()() {
std::vector<DestElementType> cvector(PyArray_SIZE((PyArrayObject *)m_arr.ptr()));
std::vector<DestElementType> cvector(PyArray_SIZE(reinterpret_cast<PyArrayObject *>(m_arr.ptr())));
copyTo(cvector);
return cvector;
}
Expand All @@ -134,9 +134,9 @@ typename NDArrayToVector<DestElementType>::TypedVector NDArrayToVector<DestEleme
* It's size is checked against the array size.
*/
template <typename DestElementType> void NDArrayToVector<DestElementType>::copyTo(TypedVector &dest) const {
if (PyArray_SIZE((PyArrayObject *)m_arr.ptr()) > 0) {
if (PyArray_SIZE(reinterpret_cast<PyArrayObject *>(m_arr.ptr())) > 0) {
throwIfSizeMismatched(dest);
CopyToImpl<DestElementType>()(std::begin(dest), (PyArrayObject *)m_arr.ptr());
CopyToImpl<DestElementType>()(std::begin(dest), reinterpret_cast<PyArrayObject *>(m_arr.ptr()));
}
}

Expand Down
15 changes: 0 additions & 15 deletions buildconfig/CMake/CppCheck_Suppressions.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -638,21 +638,6 @@ missingOverride:${CMAKE_SOURCE_DIR}/Framework/Muon/inc/MantidMuon/MuonGroupingCo
missingOverride:${CMAKE_SOURCE_DIR}/Framework/Muon/inc/MantidMuon/MuonPairingAsymmetry.h:22
missingOverride:${CMAKE_SOURCE_DIR}/Framework/Muon/inc/MantidMuon/MuonPreProcess.h:23
variableScope:${CMAKE_SOURCE_DIR}/Framework/Muon/src/EstimateMuonAsymmetryFromCounts.cpp:157
constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/Muon/src/LoadMuonNexus2.cpp:87
constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/Muon/src/PlotAsymmetryByLogValue.cpp:216
constVariableReference:${CMAKE_SOURCE_DIR}/Framework/Muon/src/PlotAsymmetryByLogValue.cpp:452
constVariableReference:${CMAKE_SOURCE_DIR}/Framework/Muon/src/PlotAsymmetryByLogValue.cpp:462
constVariableReference:${CMAKE_SOURCE_DIR}/Framework/Muon/src/PlotAsymmetryByLogValue.cpp:497
constVariableReference:${CMAKE_SOURCE_DIR}/Framework/Muon/src/PlotAsymmetryByLogValue.cpp:507
constParameterReference:${CMAKE_SOURCE_DIR}/Framework/Muon/src/PlotAsymmetryByLogValue.cpp:868
constParameterReference:${CMAKE_SOURCE_DIR}/Framework/NexusGeometry/src/NexusShapeFactory.cpp:33
missingOverride:${CMAKE_SOURCE_DIR}/Framework/Parallel/inc/MantidParallel/IO/EventsListsShmemStorage.h:32
constParameterCallback:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/core/inc/MantidPythonInterface/core/DataServiceExporter.h:160
constParameterPointer:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/core/inc/MantidPythonInterface/core/IsNone.h:26
constParameterPointer:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/core/src/Converters/CloneToNDArray.cpp:123
cstyleCast:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/core/src/Converters/NDArrayToVector.cpp:126
cstyleCast:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/core/src/Converters/NDArrayToVector.cpp:137
cstyleCast:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/core/src/Converters/NDArrayToVector.cpp:139
cstyleCast:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/core/src/Converters/NDArrayToVector.cpp:151
cstyleCast:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/core/src/Converters/NDArrayToVector.cpp:156
cstyleCast:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/core/src/Converters/PyObjectToMatrix.cpp:44
Expand Down