From 27ecd7262ee4f28c54c0169a3f26974f3fbd20bd Mon Sep 17 00:00:00 2001
From: Steven Hahn <hahnse@ornl.gov>
Date: Wed, 2 Nov 2016 18:11:48 -0400
Subject: [PATCH] Fix cppcheck v1.76 warnings.

---
 Framework/API/src/ExperimentInfo.cpp          |  2 +-
 .../Algorithms/src/CalculateCountRate.cpp     |  3 +-
 .../Crystal/src/OptimizeCrystalPlacement.cpp  |  9 ++--
 Framework/DataHandling/src/LoadBBY.cpp        |  7 +--
 .../StartAndEndTimeFromNexusFileExtractor.cpp |  4 +-
 .../src/ReflectometryTransform.cpp            | 43 +++++++++----------
 .../Geometry/src/Surfaces/SurfaceFactory.cpp  |  2 +-
 Framework/Kernel/src/MaterialXMLParser.cpp    |  3 +-
 Framework/Kernel/src/Strings.cpp              |  2 +-
 Framework/MatlabAPI/src/MatlabInterface.cpp   |  2 +-
 .../TestHelpers/src/MDEventsTestHelper.cpp    |  4 +-
 MantidPlot/src/QwtBarCurve.cpp                |  6 +--
 MantidPlot/src/Spectrogram.cpp                |  1 +
 MantidQt/API/src/ScriptRepositoryView.cpp     |  2 +-
 Vates/VatesAPI/src/PresenterUtilities.cpp     |  2 +-
 .../src/RebinnedSourcesManager.cpp            |  3 +-
 16 files changed, 48 insertions(+), 47 deletions(-)

diff --git a/Framework/API/src/ExperimentInfo.cpp b/Framework/API/src/ExperimentInfo.cpp
index d61acf54a95..938ba5dd0eb 100644
--- a/Framework/API/src/ExperimentInfo.cpp
+++ b/Framework/API/src/ExperimentInfo.cpp
@@ -683,7 +683,7 @@ class DummyException {
 public:
   std::string m_validFrom;
   std::string m_validTo;
-  DummyException(std::string validFrom, std::string validTo)
+  DummyException(const std::string &validFrom, const std::string &validTo)
       : m_validFrom(validFrom), m_validTo(validTo) {}
 };
 
diff --git a/Framework/Algorithms/src/CalculateCountRate.cpp b/Framework/Algorithms/src/CalculateCountRate.cpp
index 22629dde6ca..2f95a7a4bf5 100644
--- a/Framework/Algorithms/src/CalculateCountRate.cpp
+++ b/Framework/Algorithms/src/CalculateCountRate.cpp
@@ -212,14 +212,13 @@ void CalculateCountRate::calcRateLog(
   double dTRangeMin = static_cast<double>(m_TRangeMin.totalNanoseconds());
   double dTRangeMax = static_cast<double>(m_TRangeMax.totalNanoseconds());
   std::vector<MantidVec> Buff;
-  int nThreads;
 
 #pragma omp parallel
   {
+    int nThreads = PARALLEL_NUMBER_OF_THREADS;
 #pragma omp single
     {
       // initialize thread's histogram buffer
-      nThreads = PARALLEL_NUMBER_OF_THREADS;
       Buff.resize(nThreads);
     }
     auto nThread = PARALLEL_THREAD_NUMBER;
diff --git a/Framework/Crystal/src/OptimizeCrystalPlacement.cpp b/Framework/Crystal/src/OptimizeCrystalPlacement.cpp
index c05e0e9aa40..e7f720798cf 100644
--- a/Framework/Crystal/src/OptimizeCrystalPlacement.cpp
+++ b/Framework/Crystal/src/OptimizeCrystalPlacement.cpp
@@ -36,9 +36,12 @@ DECLARE_ALGORITHM(OptimizeCrystalPlacement)
 
 class OrEnabledWhenProperties : public Kernel::IPropertySettings {
 public:
-  OrEnabledWhenProperties(std::string prop1Name, ePropertyCriterion prop1Crit,
-                          std::string prop1Value, std::string prop2Name,
-                          ePropertyCriterion prop2Crit, std::string prop2Value)
+  OrEnabledWhenProperties(const std::string &prop1Name,
+                          ePropertyCriterion prop1Crit,
+                          const std::string &prop1Value,
+                          const std::string &prop2Name,
+                          ePropertyCriterion prop2Crit,
+                          const std::string &prop2Value)
       : IPropertySettings(), propName1(prop1Name), propName2(prop2Name),
         Criteria1(prop1Crit), Criteria2(prop2Crit), value1(prop1Value),
         value2(prop2Value)
diff --git a/Framework/DataHandling/src/LoadBBY.cpp b/Framework/DataHandling/src/LoadBBY.cpp
index e93e9e638ae..b109d4d6ba4 100644
--- a/Framework/DataHandling/src/LoadBBY.cpp
+++ b/Framework/DataHandling/src/LoadBBY.cpp
@@ -689,12 +689,13 @@ void LoadBBY::loadEvents(API::Progress &prog, const char *progMsg,
     case 5:
     case 6:
     case 7:
-    case 8:
       event_ended = (c & 0xC0) != 0xC0;
       if (!event_ended)
         c &= 0x3F;
-
-      dt |= (c & 0xFF) << (5 + 6 * (state - 3)); // set bit 6...
+      // avoid shifting by > 32 bits
+      // identical to dt |= 0
+      if (state != 8)
+        dt |= (c & 0xFF) << (5 + 6 * (state - 3)); // set bit 6...
       break;
     }
     state++;
diff --git a/Framework/DataHandling/src/StartAndEndTimeFromNexusFileExtractor.cpp b/Framework/DataHandling/src/StartAndEndTimeFromNexusFileExtractor.cpp
index 362af848dd8..289abc173e6 100644
--- a/Framework/DataHandling/src/StartAndEndTimeFromNexusFileExtractor.cpp
+++ b/Framework/DataHandling/src/StartAndEndTimeFromNexusFileExtractor.cpp
@@ -139,7 +139,7 @@ Mantid::Kernel::DateAndTime extractDateAndTime(TimeType type,
  * @return the start time
  * @throws if the the start time cannot be extracted
  */
-Mantid::Kernel::DateAndTime extractStartTime(std::string filename) {
+Mantid::Kernel::DateAndTime extractStartTime(const std::string &filename) {
   return extractDateAndTime(TimeType::StartTime, filename);
 }
 
@@ -149,7 +149,7 @@ Mantid::Kernel::DateAndTime extractStartTime(std::string filename) {
  * @return the start time
  * @throws if the the start time cannot be extracted
  */
-Mantid::Kernel::DateAndTime extractEndTime(std::string filename) {
+Mantid::Kernel::DateAndTime extractEndTime(const std::string &filename) {
   return extractDateAndTime(TimeType::EndTime, filename);
 }
 
diff --git a/Framework/DataObjects/src/ReflectometryTransform.cpp b/Framework/DataObjects/src/ReflectometryTransform.cpp
index c87dad39f97..b328094282f 100644
--- a/Framework/DataObjects/src/ReflectometryTransform.cpp
+++ b/Framework/DataObjects/src/ReflectometryTransform.cpp
@@ -48,33 +48,32 @@ void writeRow(boost::shared_ptr<Mantid::DataObjects::TableWorkspace> &vertexes,
 *  Adds the column headings to a table
 *  @param vertexes : Table to which the columns are written to.
 */
-void addColumnHeadings(
-    boost::shared_ptr<Mantid::DataObjects::TableWorkspace> &vertexes,
-    std::string outputDimensions) {
+void addColumnHeadings(Mantid::DataObjects::TableWorkspace &vertexes,
+                       const std::string &outputDimensions) {
 
   if (outputDimensions == "Q (lab frame)") {
-    vertexes->addColumn("double", "Qx");
-    vertexes->addColumn("double", "Qy");
-    vertexes->addColumn("int", "OriginIndex");
-    vertexes->addColumn("int", "OriginBin");
-    vertexes->addColumn("double", "CellSignal");
-    vertexes->addColumn("double", "CellError");
+    vertexes.addColumn("double", "Qx");
+    vertexes.addColumn("double", "Qy");
+    vertexes.addColumn("int", "OriginIndex");
+    vertexes.addColumn("int", "OriginBin");
+    vertexes.addColumn("double", "CellSignal");
+    vertexes.addColumn("double", "CellError");
   }
   if (outputDimensions == "P (lab frame)") {
-    vertexes->addColumn("double", "Pi+Pf");
-    vertexes->addColumn("double", "Pi-Pf");
-    vertexes->addColumn("int", "OriginIndex");
-    vertexes->addColumn("int", "OriginBin");
-    vertexes->addColumn("double", "CellSignal");
-    vertexes->addColumn("double", "CellError");
+    vertexes.addColumn("double", "Pi+Pf");
+    vertexes.addColumn("double", "Pi-Pf");
+    vertexes.addColumn("int", "OriginIndex");
+    vertexes.addColumn("int", "OriginBin");
+    vertexes.addColumn("double", "CellSignal");
+    vertexes.addColumn("double", "CellError");
   }
   if (outputDimensions == "K (incident, final)") {
-    vertexes->addColumn("double", "Ki");
-    vertexes->addColumn("double", "Kf");
-    vertexes->addColumn("int", "OriginIndex");
-    vertexes->addColumn("int", "OriginBin");
-    vertexes->addColumn("double", "CellSignal");
-    vertexes->addColumn("double", "CellError");
+    vertexes.addColumn("double", "Ki");
+    vertexes.addColumn("double", "Kf");
+    vertexes.addColumn("int", "OriginIndex");
+    vertexes.addColumn("int", "OriginBin");
+    vertexes.addColumn("double", "CellSignal");
+    vertexes.addColumn("double", "CellError");
   }
 }
 }
@@ -464,7 +463,7 @@ MatrixWorkspace_sptr ReflectometryTransform::executeNormPoly(
   std::vector<specnum_t> specNumberMapping;
   std::vector<detid_t> detIDMapping;
   // Create a table for the output if we want to debug vertex positioning
-  addColumnHeadings(vertexes, outputDimensions);
+  addColumnHeadings(*vertexes, outputDimensions);
   for (size_t i = 0; i < nHistos; ++i) {
     IDetector_const_sptr detector = inputWS->getDetector(i);
     if (!detector || detector->isMasked() || detector->isMonitor()) {
diff --git a/Framework/Geometry/src/Surfaces/SurfaceFactory.cpp b/Framework/Geometry/src/Surfaces/SurfaceFactory.cpp
index 6de9aa18a83..1e3e177614f 100644
--- a/Framework/Geometry/src/Surfaces/SurfaceFactory.cpp
+++ b/Framework/Geometry/src/Surfaces/SurfaceFactory.cpp
@@ -88,7 +88,7 @@ void SurfaceFactory::registerSurface()
 namespace {
 class KeyEquals {
 public:
-  explicit KeyEquals(std::string key) : m_key(std::move(key)) {}
+  explicit KeyEquals(const std::string &key) : m_key(key) {}
   bool
   operator()(const std::pair<std::string, std::unique_ptr<Surface>> &element) {
     return m_key == element.first;
diff --git a/Framework/Kernel/src/MaterialXMLParser.cpp b/Framework/Kernel/src/MaterialXMLParser.cpp
index c9c91ae43e0..1e110f55d4e 100644
--- a/Framework/Kernel/src/MaterialXMLParser.cpp
+++ b/Framework/Kernel/src/MaterialXMLParser.cpp
@@ -68,7 +68,8 @@ struct TypedBuilderHandle final : public BuilderHandle {
   typedef typename std::remove_const<
       typename std::remove_reference<ArgType>::type>::type ValueType;
 
-  TypedBuilderHandle(BuilderMethod<ArgType> m) : BuilderHandle(), m_method(m) {}
+  explicit TypedBuilderHandle(BuilderMethod<ArgType> m)
+      : BuilderHandle(), m_method(m) {}
 
   void operator()(MaterialBuilder &builder,
                   const std::string &value) const override {
diff --git a/Framework/Kernel/src/Strings.cpp b/Framework/Kernel/src/Strings.cpp
index aa0550b5f25..94977a619b5 100644
--- a/Framework/Kernel/src/Strings.cpp
+++ b/Framework/Kernel/src/Strings.cpp
@@ -411,7 +411,7 @@ void writeMCNPX(const std::string &Line, std::ostream &OX) {
  *  @param Ln :: line component to strip
  *  @return vector of components
  */
-std::vector<std::string> StrParts(std::string Ln) {
+std::vector<std::string> StrParts(const std::string &Ln) {
   std::vector<std::string> Out;
   std::string Part;
   while (section(Ln, Part))
diff --git a/Framework/MatlabAPI/src/MatlabInterface.cpp b/Framework/MatlabAPI/src/MatlabInterface.cpp
index 071d2ebc81b..d171b839024 100644
--- a/Framework/MatlabAPI/src/MatlabInterface.cpp
+++ b/Framework/MatlabAPI/src/MatlabInterface.cpp
@@ -302,8 +302,8 @@ mxArray *ixbcreateclassarray(const char *class_name, int *n) {
   */
 int CreateFrameworkManager(int nlhs, mxArray *plhs[], int nrhs,
                            const mxArray *prhs[]) {
-  mwSize dims[2] = {1, 1};
   try {
+    mwSize dims[2] = {1, 1};
     FrameworkManagerImpl &fmgr = FrameworkManager::Instance();
     plhs[0] = mxCreateNumericArray(2, dims, mxUINT64_CLASS, mxREAL);
     uint64_t *data = (uint64_t *)mxGetData(plhs[0]);
diff --git a/Framework/TestHelpers/src/MDEventsTestHelper.cpp b/Framework/TestHelpers/src/MDEventsTestHelper.cpp
index dad353bac42..63d708ccfbe 100644
--- a/Framework/TestHelpers/src/MDEventsTestHelper.cpp
+++ b/Framework/TestHelpers/src/MDEventsTestHelper.cpp
@@ -216,8 +216,8 @@ std::vector<MDLeanEvent<1>> makeMDEvents1(size_t num) {
  */
 Mantid::DataObjects::MDHistoWorkspace_sptr
 makeFakeMDHistoWorkspace(double signal, size_t numDims, size_t numBins,
-                         coord_t max, double errorSquared, std::string name,
-                         double numEvents) {
+                         coord_t max, double errorSquared,
+                         const std::string &name, double numEvents) {
   // Create MDFrame of General Frame type
   Mantid::Geometry::GeneralFrame frame(
       Mantid::Geometry::GeneralFrame::GeneralFrameDistance, "m");
diff --git a/MantidPlot/src/QwtBarCurve.cpp b/MantidPlot/src/QwtBarCurve.cpp
index 54c05370ba2..ac81504050b 100644
--- a/MantidPlot/src/QwtBarCurve.cpp
+++ b/MantidPlot/src/QwtBarCurve.cpp
@@ -32,10 +32,8 @@
 
 QwtBarCurve::QwtBarCurve(BarStyle style, Table *t, const QString &xColName,
                          const QString &name, int startRow, int endRow)
-    : DataCurve(t, xColName, name, startRow, endRow) {
-  bar_offset = 0;
-  bar_gap = 0;
-  bar_style = style;
+    : DataCurve(t, xColName, name, startRow, endRow), bar_gap{0}, bar_offset{0},
+      bar_style{style} {
 
   setPen(QPen(Qt::black, 1, Qt::SolidLine));
   setBrush(QBrush(Qt::red));
diff --git a/MantidPlot/src/Spectrogram.cpp b/MantidPlot/src/Spectrogram.cpp
index 8d092ad7a41..1e543976b0c 100644
--- a/MantidPlot/src/Spectrogram.cpp
+++ b/MantidPlot/src/Spectrogram.cpp
@@ -1022,6 +1022,7 @@ void Spectrogram::loadFromProject(const std::string &lines) {
     std::string policyStr = tsv.sections("ColorPolicy").front();
     int policy = 0;
     Strings::convert<int>(policyStr, policy);
+    // cppcheck-suppress knownConditionTrueFalse
     if (policy == GrayScale)
       setGrayScale();
     else if (policy == Default)
diff --git a/MantidQt/API/src/ScriptRepositoryView.cpp b/MantidQt/API/src/ScriptRepositoryView.cpp
index 6226c6d2372..c01d40274e5 100644
--- a/MantidQt/API/src/ScriptRepositoryView.cpp
+++ b/MantidQt/API/src/ScriptRepositoryView.cpp
@@ -154,7 +154,7 @@ ScriptRepositoryView::ScriptRepositoryView(QWidget *parent)
     // create the model
     model = new RepoModel(this);
 
-  } catch (EXC_OPTIONS ex) {
+  } catch (EXC_OPTIONS &ex) {
     if (ex == NODIRECTORY)
       // probably the user change mind. He does not want to install any more.
       QMessageBox::warning(this, "Installation Failed",
diff --git a/Vates/VatesAPI/src/PresenterUtilities.cpp b/Vates/VatesAPI/src/PresenterUtilities.cpp
index f6f32fa8883..4062c83c404 100644
--- a/Vates/VatesAPI/src/PresenterUtilities.cpp
+++ b/Vates/VatesAPI/src/PresenterUtilities.cpp
@@ -125,7 +125,7 @@ createFactoryChainForHistoWorkspace(ThresholdRange_scptr threshold,
 * @param name: the input name
 * @return a name with a time stamp
 */
-std::string createTimeStampedName(std::string name) {
+std::string createTimeStampedName(const std::string &name) {
   auto currentTime =
       std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
   std::string timeInReadableFormat = std::string(std::ctime(&currentTime));
diff --git a/Vates/VatesSimpleGui/ViewWidgets/src/RebinnedSourcesManager.cpp b/Vates/VatesSimpleGui/ViewWidgets/src/RebinnedSourcesManager.cpp
index 42963509683..087483d000e 100644
--- a/Vates/VatesSimpleGui/ViewWidgets/src/RebinnedSourcesManager.cpp
+++ b/Vates/VatesSimpleGui/ViewWidgets/src/RebinnedSourcesManager.cpp
@@ -711,8 +711,7 @@ std::string RebinnedSourcesManager::saveToProject() {
 void RebinnedSourcesManager::loadFromProject(const std::string &lines) {
   MantidQt::API::TSVSerialiser tsv(lines);
 
-  std::string rebinWorkspaceName, originalWorkspaceName, rebinProxyName,
-      originalProxyName;
+  std::string rebinWorkspaceName, originalWorkspaceName, rebinProxyName;
   tsv.selectLine("RebinnedWorkspaceName");
   tsv >> rebinWorkspaceName;
   tsv.selectLine("OriginalWorkspaceName");
-- 
GitLab