Commit 39a6998d authored by David Fairbrother's avatar David Fairbrother
Browse files

Fix Cppcheck warnings for 1.90

parent a200387f
......@@ -117,8 +117,8 @@ Expression &Expression::operator=(const Expression &expr) {
m_funct = expr.m_funct;
m_op = expr.m_op;
m_terms = expr.m_terms;
// m_expr = expr.m_expr;
// m_tokens = expr.m_tokens;
m_expr = expr.m_expr;
m_tokens = expr.m_tokens;
return *this;
}
......
......@@ -559,10 +559,11 @@ std::vector<std::string> IFunction::getParameterNames() const {
* @param handler :: A new handler
*/
void IFunction::setHandler(std::unique_ptr<FunctionHandler> handler) {
m_handler = std::move(handler);
if (handler && handler->function().get() != this) {
throw std::runtime_error("Function handler points to a different function");
}
m_handler = std::move(handler);
m_handler->init();
}
......@@ -661,6 +662,7 @@ private:
/// @param attr :: The attribute to copy from.
IFunction::Attribute &IFunction::Attribute::operator=(const Attribute &attr) {
m_data = attr.m_data;
m_quoteValue = attr.m_quoteValue;
return *this;
}
......
......@@ -78,7 +78,6 @@ Indexing::SpectrumIndexSet IndexProperty::getIndices() const {
static_cast<Indexing::SpectrumNumber>(static_cast<int32_t>(max)));
}
} else {
// cppcheck-suppress constArgument
MSVC_DIAG_OFF(4244);
switch (type) {
case IndexType::WorkspaceIndex:
......
......@@ -1940,8 +1940,6 @@ MatrixWorkspace::findY(double value,
if (std::isnan(value)) {
for (int64_t i = idx.first; i < numHists; ++i) {
const auto &Y = this->y(i);
// https://trac.cppcheck.net/ticket/9237 if init buggy with cppcheck
// cppcheck-suppress stlIfFind
if (auto it = std::find_if(std::next(Y.begin(), idx.second), Y.end(),
[](double v) { return std::isnan(v); });
it != Y.end()) {
......@@ -1952,7 +1950,6 @@ MatrixWorkspace::findY(double value,
} else {
for (int64_t i = idx.first; i < numHists; ++i) {
const auto &Y = this->y(i);
// cppcheck-suppress stlIfFind
if (auto it = std::find(std::next(Y.begin(), idx.second), Y.end(), value);
it != Y.end()) {
out = {i, std::distance(Y.begin(), it)};
......
......@@ -150,7 +150,7 @@ double ParamFunction::getParameter(const std::string &name) const {
*/
bool ParamFunction::hasParameter(const std::string &name) const {
return std::find(m_parameterNames.cbegin(), m_parameterNames.cend(), name) !=
m_parameterNames.end();
m_parameterNames.cend();
}
/**
......
......@@ -186,7 +186,7 @@ public:
foundAlg = ("Cat" == descItr->category) &&
("ToyAlgorithm" == descItr->name) &&
("Dog" == descItr->alias) && (1 == descItr->version);
descItr++;
++descItr;
}
TS_ASSERT(foundAlg);
......
......@@ -104,7 +104,6 @@ public:
void test_Shared_Pointer() {
FunctionProperty prop("fun");
std::string error;
boost::shared_ptr<FunctionPropertyTest_Function> fun_p(
new FunctionPropertyTest_Function);
TS_ASSERT(fun_p);
......
......@@ -555,8 +555,7 @@ private:
LogManager runInfo;
const std::string name = "T_prop";
runInfo.addProperty<T>(name, value);
int result(-1);
result = runInfo.getPropertyAsIntegerValue(name);
int result = runInfo.getPropertyAsIntegerValue(name);
TS_ASSERT_THROWS_NOTHING(result = runInfo.getPropertyAsIntegerValue(name));
TS_ASSERT_EQUALS(value, static_cast<T>(result));
}
......@@ -580,12 +579,11 @@ public:
}
void test_Accessing_Single_Value_From_Times_Series_A_Large_Number_Of_Times() {
double value(0.0);
for (size_t i = 0; i < 20000; ++i) {
value = m_testRun.getPropertyAsSingleValue(m_propName);
// This has an observable side-effect of calling, so we don't need
// to store its return value
m_testRun.getPropertyAsSingleValue(m_propName);
}
// Enure variable is used so that it is not optimised away by the compiler
value += 1.0;
}
LogManager m_testRun;
......
......@@ -324,7 +324,6 @@ public:
void test_attribute_domain_range() {
multi.clearDomainIndices();
multi.setLocalAttributeValue(0, "domains", "0-2");
return;
multi.setLocalAttributeValue(1, "domains", "i");
multi.setLocalAttributeValue(2, "domains", "i");
......
......@@ -632,10 +632,8 @@ public:
void test_Accessing_Single_Value_From_Times_Series_A_Large_Number_Of_Times() {
double value(0.0);
for (size_t i = 0; i < 20000; ++i) {
value = m_testRun.getPropertyAsSingleValue(m_propName);
m_testRun.getPropertyAsSingleValue(m_propName);
}
// Enure variable is used so that it is not optimised away by the compiler
value += 1.0;
}
Run m_testRun;
......
......@@ -404,7 +404,7 @@ void ConjoinXRuns::exec() {
<< ". Reason: \"" << e.what() << "\". Skipping.\n";
sampleLogsBehaviour.resetSampleLogs(temp);
// remove the skipped one from the list
m_inputWS.erase(it);
it = m_inputWS.erase(it);
--it;
} else {
throw std::invalid_argument(e);
......
......@@ -220,11 +220,10 @@ void CorrectKiKf::execEvent() {
PARALLEL_FOR_IF(Kernel::threadSafe(*outputWS))
for (int64_t i = 0; i < numHistograms; ++i) {
PARALLEL_START_INTERUPT_REGION
double Efi = 0;
// Now get the detector object for this histogram to check if monitor
// or to get Ef for indirect geometry
if (emodeStr == "Indirect") {
double Efi = 0;
if (efixedProp != EMPTY_DBL()) {
Efi = efixedProp;
// If a DetectorGroup is present should provide a value as a property
......
......@@ -432,7 +432,6 @@ void CreateGroupingWorkspace::exec() {
sortnames = true;
GroupNames = "";
int maxRecurseDepth = this->getProperty("MaxRecursionDepth");
// cppcheck-suppress syntaxError
PRAGMA_OMP(parallel for schedule(dynamic, 1) )
for (int num = 0; num < 300; ++num) {
......
......@@ -590,11 +590,10 @@ void DiffractionFocussing2::determineRebinParameters() {
nGroups = group2minmax.size(); // Number of unique groups
double Xmin, Xmax, step;
const int64_t xPoints = nPoints + 1;
// Iterator over all groups to create the new X vectors
for (gpit = group2minmax.begin(); gpit != group2minmax.end(); gpit++) {
for (gpit = group2minmax.begin(); gpit != group2minmax.end(); ++gpit) {
double Xmin, Xmax, step;
Xmin = (gpit->second).first;
Xmax = (gpit->second).second;
......
......@@ -1771,7 +1771,6 @@ double FitPeaks::fitFunctionSD(
errorid << ": " << e.what();
g_log.warning() << "While fitting " + errorid.str();
return DBL_MAX; // probably the wrong thing to do
throw std::runtime_error("While fitting " + errorid.str());
}
// Retrieve result
......@@ -1847,7 +1846,6 @@ double FitPeaks::fitFunctionMD(API::IFunction_sptr fit_function,
double chi2 = DBL_MAX;
if (fitStatus == "success") {
chi2 = fit->getProperty("OutputChi2overDoF");
fit_function = fit->getProperty("Function");
}
return chi2;
......@@ -1883,9 +1881,8 @@ double FitPeaks::fitFunctionHighBackground(
createMatrixWorkspace(vec_x, vec_y, vec_e);
// Fit peak with background
double cost = fitFunctionSD(fit, peakfunction, bkgdfunc, reduced_bkgd_ws, 0,
vec_x.front(), vec_x.back(), expected_peak_center,
observe_peak_shape, false);
fitFunctionSD(fit, peakfunction, bkgdfunc, reduced_bkgd_ws, 0, vec_x.front(),
vec_x.back(), expected_peak_center, observe_peak_shape, false);
// add the reduced background back
bkgdfunc->setParameter(0, bkgdfunc->getParameter(0) +
......@@ -1893,9 +1890,9 @@ double FitPeaks::fitFunctionHighBackground(
bkgdfunc->setParameter(1, bkgdfunc->getParameter(1) +
high_bkgd_function->getParameter(1));
cost = fitFunctionSD(fit, peakfunction, bkgdfunc, m_inputMatrixWS, ws_index,
vec_x.front(), vec_x.back(), expected_peak_center, false,
false);
double cost = fitFunctionSD(fit, peakfunction, bkgdfunc, m_inputMatrixWS,
ws_index, vec_x.front(), vec_x.back(),
expected_peak_center, false, false);
return cost;
}
......
......@@ -456,10 +456,9 @@ void GenerateEventsFilter::setFilterByTimeOnly() {
int64_t curtime_ns = m_startTime.totalNanoseconds();
int wsindex = 0;
while (curtime_ns < m_stopTime.totalNanoseconds()) {
int64_t deltatime_ns;
for (size_t id = 0; id < numtimeintervals; ++id) {
// get next time interval value
deltatime_ns = vec_dtimens[id];
int64_t deltatime_ns = vec_dtimens[id];
// Calculate next.time
int64_t nexttime_ns = curtime_ns + deltatime_ns;
bool breaklater = false;
......@@ -831,7 +830,6 @@ void GenerateEventsFilter::makeFilterBySingleValue(
// Initialize control parameters
bool lastGood = false;
bool isGood = false;
time_duration tol = DateAndTime::durationFromSeconds(TimeTolerance);
int numgood = 0;
DateAndTime lastTime, currT;
......@@ -844,8 +842,8 @@ void GenerateEventsFilter::makeFilterBySingleValue(
currT = m_dblLog->nthTime(i);
// A good value?
isGood = identifyLogEntry(i, currT, lastGood, min, max, startTime, stopTime,
filterIncrease, filterDecrease);
bool isGood = identifyLogEntry(i, currT, lastGood, min, max, startTime,
stopTime, filterIncrease, filterDecrease);
if (isGood)
numgood++;
......@@ -1219,7 +1217,6 @@ void GenerateEventsFilter::makeMultipleFiltersByValuesPartialLog(
double currValue = m_dblLog->nthValue(i);
// Filter out by time and direction (optional)
bool intime = true;
if (currTime < startTime) {
// case i. Too early, do nothing
createsplitter = false;
......@@ -1254,130 +1251,127 @@ void GenerateEventsFilter::makeMultipleFiltersByValuesPartialLog(
prevDirection = direction;
// Examine log value for filter
if (intime) {
// Determine whether direction is fine
bool correctdir = true;
if (filterIncrease && filterDecrease) {
// Both direction is fine
// Determine whether direction is fine
bool correctdir = true;
if (filterIncrease && filterDecrease) {
// Both direction is fine
correctdir = true;
} else {
// Filter out one direction
if (filterIncrease && direction > 0)
correctdir = true;
} else {
// Filter out one direction
if (filterIncrease && direction > 0)
correctdir = true;
else if (filterDecrease && direction < 0)
correctdir = true;
else if (direction == 0)
throw runtime_error("Direction is not determined.");
else
correctdir = false;
} // END-IF-ELSE: Direction
// Treat the log entry based on: changing direction (+ time range)
if (correctdir) {
// Check this value whether it falls into any range
size_t index = searchValue(logvalueranges, currValue);
bool valueWithinMinMax = true;
if (index > logvalueranges.size()) {
// Out of range
valueWithinMinMax = false;
}
else if (filterDecrease && direction < 0)
correctdir = true;
else if (direction == 0)
throw runtime_error("Direction is not determined.");
else
correctdir = false;
} // END-IF-ELSE: Direction
// Treat the log entry based on: changing direction (+ time range)
if (correctdir) {
// Check this value whether it falls into any range
size_t index = searchValue(logvalueranges, currValue);
bool valueWithinMinMax = true;
if (index > logvalueranges.size()) {
// Out of range
valueWithinMinMax = false;
}
if (g_log.is(Logger::Priority::PRIO_DEBUG)) {
stringstream dbss;
dbss << "[DBx257] Examine Log Index " << i
<< ", Value = " << currValue << ", Data Range Index = " << index
<< "; "
<< "Group Index = " << indexwsindexmap[index / 2]
<< " (log value range vector size = " << logvalueranges.size()
<< "): ";
if (index == 0)
dbss << logvalueranges[index] << ", " << logvalueranges[index + 1];
else if (index == logvalueranges.size())
dbss << logvalueranges[index - 1] << ", " << logvalueranges[index];
else if (valueWithinMinMax)
dbss << logvalueranges[index - 1] << ", " << logvalueranges[index]
<< ", " << logvalueranges[index + 1];
g_log.debug(dbss.str());
}
if (g_log.is(Logger::Priority::PRIO_DEBUG)) {
stringstream dbss;
dbss << "[DBx257] Examine Log Index " << i << ", Value = " << currValue
<< ", Data Range Index = " << index << "; "
<< "Group Index = " << indexwsindexmap[index / 2]
<< " (log value range vector size = " << logvalueranges.size()
<< "): ";
if (index == 0)
dbss << logvalueranges[index] << ", " << logvalueranges[index + 1];
else if (index == logvalueranges.size())
dbss << logvalueranges[index - 1] << ", " << logvalueranges[index];
else if (valueWithinMinMax)
dbss << logvalueranges[index - 1] << ", " << logvalueranges[index]
<< ", " << logvalueranges[index + 1];
g_log.debug(dbss.str());
}
if (valueWithinMinMax) {
if (index % 2 == 0) {
// [Situation] Falls in the interval
currindex = indexwsindexmap[index / 2];
if (currindex != lastindex && start.totalNanoseconds() == 0) {
// Group index is different from last and start is not set up: new
// a region!
newsplitter = true;
} else if (currindex != lastindex && start.totalNanoseconds() > 0) {
// Group index is different from last and start is set up: close
// a region and new a region
if (valueWithinMinMax) {
if (index % 2 == 0) {
// [Situation] Falls in the interval
currindex = indexwsindexmap[index / 2];
if (currindex != lastindex && start.totalNanoseconds() == 0) {
// Group index is different from last and start is not set up: new
// a region!
newsplitter = true;
} else if (currindex != lastindex && start.totalNanoseconds() > 0) {
// Group index is different from last and start is set up: close
// a region and new a region
stop = currTime;
createsplitter = true;
newsplitter = true;
} else if (currindex == lastindex && start.totalNanoseconds() > 0) {
// Still of the group index
if (i == iend) {
// Last entry in this section of log. Need to flag to close the
// pair
stop = currTime;
createsplitter = true;
newsplitter = true;
} else if (currindex == lastindex && start.totalNanoseconds() > 0) {
// Still of the group index
if (i == iend) {
// Last entry in this section of log. Need to flag to close the
// pair
stop = currTime;
createsplitter = true;
newsplitter = false;
} else {
// Do nothing
;
}
newsplitter = false;
} else {
// An impossible situation
std::stringstream errmsg;
double lastvalue = m_dblLog->nthValue(i - 1);
errmsg << "Impossible to have currindex == lastindex == "
<< currindex
<< ", while start is not init. Log Index = " << i
<< "\t value = " << currValue << "\t, Index = " << index
<< " in range " << logvalueranges[index] << ", "
<< logvalueranges[index + 1]
<< "; Last value = " << lastvalue;
throw std::runtime_error(errmsg.str());
// Do nothing
;
}
} // [In-bound: Inside interval]
else {
// [Situation] Fall between interval (which is not likley happen)
currindex = -1;
g_log.warning()
<< "Not likely to happen! Current value = " << currValue
<< " is within value range but its index = " << index
<< " has no map to group index. "
<< "\n";
if (start.totalNanoseconds() > 0) {
// Close the interval pair if it has been started.
stop = currTime;
createsplitter = true;
}
} // [In-bound: Between interval]
} else {
// Out of a range: check whether there is a splitter started
} else {
// An impossible situation
std::stringstream errmsg;
double lastvalue = m_dblLog->nthValue(i - 1);
errmsg << "Impossible to have currindex == lastindex == "
<< currindex
<< ", while start is not init. Log Index = " << i
<< "\t value = " << currValue << "\t, Index = " << index
<< " in range " << logvalueranges[index] << ", "
<< logvalueranges[index + 1]
<< "; Last value = " << lastvalue;
throw std::runtime_error(errmsg.str());
}
} // [In-bound: Inside interval]
else {
// [Situation] Fall between interval (which is not likley happen)
currindex = -1;
g_log.warning() << "Not likely to happen! Current value = "
<< currValue
<< " is within value range but its index = " << index
<< " has no map to group index. "
<< "\n";
if (start.totalNanoseconds() > 0) {
// End situation
// Close the interval pair if it has been started.
stop = currTime;
createsplitter = true;
}
} // [Out-bound]
} // [CORRECT DIRECTION]
else {
// Log Index i falls out b/c out of wrong direction
} // [In-bound: Between interval]
} else {
// Out of a range: check whether there is a splitter started
currindex = -1;
// Condition to generate a Splitter (close parenthesis)
if (!correctdir && start.totalNanoseconds() > 0) {
if (start.totalNanoseconds() > 0) {
// End situation
stop = currTime;
createsplitter = true;
}
} // [Out-bound]
} // [CORRECT DIRECTION]
else {
// Log Index i falls out b/c out of wrong direction
currindex = -1;
// Condition to generate a Splitter (close parenthesis)
if (!correctdir && start.totalNanoseconds() > 0) {
stop = currTime;
createsplitter = true;
}
} // ENDIF (log entry in specified time)
}
// d) Create Splitter
if (createsplitter) {
......
......@@ -721,7 +721,7 @@ void GetDetOffsetsMultiPeaks::fitPeaksOffset(
// Set up GSL minimzer
const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex;
gsl_multimin_fminimizer *s = nullptr;
gsl_vector *ss, *x;
gsl_multimin_function minex_func;
......@@ -729,7 +729,6 @@ void GetDetOffsetsMultiPeaks::fitPeaksOffset(
size_t nopt = 1;
size_t iter = 0;
int status = 0;
double size;
/* Starting point */
x = gsl_vector_alloc(nopt);
......@@ -744,7 +743,7 @@ void GetDetOffsetsMultiPeaks::fitPeaksOffset(
minex_func.f = &gsl_costFunction;
minex_func.params = &params;
s = gsl_multimin_fminimizer_alloc(T, nopt);
gsl_multimin_fminimizer *s = gsl_multimin_fminimizer_alloc(T, nopt);
gsl_multimin_fminimizer_set(s, &minex_func, x, ss);
do {
......@@ -753,7 +752,7 @@ void GetDetOffsetsMultiPeaks::fitPeaksOffset(
if (status)
break;
size = gsl_multimin_fminimizer_size(s);
double size = gsl_multimin_fminimizer_size(s);
status = gsl_multimin_test_size(size, 1e-4);
} while (status == GSL_CONTINUE && iter < 50);
......
......@@ -755,14 +755,13 @@ double fitDIFCtZeroDIFA(std::vector<double> &peaks, double &difc, double &t0,
size_t iter = 0; // number of iterations
const size_t MAX_ITER = 75 * numParams;
int status = 0;
double size;
do {
iter++;
status = gsl_multimin_fminimizer_iterate(minimizer);
if (status)
break;
size = gsl_multimin_fminimizer_size(minimizer);
double size = gsl_multimin_fminimizer_size(minimizer);
status = gsl_multimin_test_size(size, 1e-4);
} while (status == GSL_CONTINUE && iter < MAX_ITER);
......
......@@ -96,30 +96,22 @@ void fourInputsCorrectedAndErrors(
const auto diag1 = 1. / f1;
const auto off1 = (f1 - 1.) / f1;
Eigen::Matrix4d F1m;
// Suppress warnings about suspicious init with Eigen
// cppcheck-suppress constStatement
F1m << 1., 0., 0., 0., 0., 1., 0., 0., off1, 0., diag1, 0., 0., off1, 0.,
diag1;
const auto diag2 = 1. / f2;
const auto off2 = (f2 - 1.) / f2;
Eigen::Matrix4d F2m;
// cppcheck-suppress constStatement
F2m << 1., 0., 0., 0., off2, diag2, 0., 0., 0., 0., 1., 0., 0., 0., off2,
diag2;
const auto diag3 = (p1 - 1.) / (2. * p1 - 1.);
const auto off3 = p1 / (2. * p1 - 1);
Eigen::Matrix4d P1m;
// cppcheck-suppress constStatement
P1m << diag3, 0, off3, 0, 0, diag3, 0, off3, off3, 0, diag3, 0, 0, off3, 0,
diag3;
const auto diag4 = (p2 - 1.) / (2. * p2 - 1.);
const auto off4 = p2 / (2. * p2 - 1.);
Eigen::Matrix4d P2m;
// cppcheck-suppress constStatement
P2m << diag4, off4, 0., 0., off4, diag4, 0., 0., 0., 0., diag4, off4, 0., 0.,
off4, diag4;
const Eigen::Vector4d intensities(ppy, pmy, mpy, mmy);
......@@ -131,26 +123,18 @@ void fourInputsCorrectedAndErrors(
// the matrices above, multiplied by the error.
const auto elemE1 = -1. / pow<2>(f1) * f1E;
Eigen::Matrix4d F1Em;
// cppcheck-suppress constStatement
F1Em << 0., 0., 0., 0., 0., 0., 0., 0., -elemE1, 0., elemE1, 0., 0., -elemE1,
0., elemE1;