From 796df28db73704bf4f9de35d90392ced249d2570 Mon Sep 17 00:00:00 2001
From: Nick Draper <nick.draper@stfc.ac.uk>
Date: Mon, 18 Nov 2013 15:00:01 +0000
Subject: [PATCH] re #8466 cppcheck warnings

---
 Code/Mantid/Build/CMake/CppCheckSetup.cmake   |   4 +-
 .../Build/CMake/CppCheck_Suppressions.txt     |  11 +
 Code/Mantid/Build/CMake/FindCppcheck.cmake    |   4 +-
 .../Framework/API/src/ParamFunction.cpp       |   2 +-
 .../Algorithms/src/ConvertAxisByFormula.cpp   |   2 -
 .../src/DetectorEfficiencyCorUser.cpp         |   3 +-
 .../Framework/Crystal/src/LoadIsawPeaks.cpp   |   7 +-
 .../Crystal/src/PredictFractionalPeaks.cpp    | 372 +++++++++---------
 .../CurveFitting/src/ReflectivityMulf.cpp     |   7 -
 .../DataHandling/src/FindDetectorsPar.cpp     |   1 -
 .../DataHandling/src/SaveCanSAS1D.cpp         |   4 +-
 .../Geometry/src/Math/ORourkeIntersection.cpp |   3 +-
 .../Kernel/inc/MantidKernel/Strings.h         |   2 +-
 Code/Mantid/Framework/Kernel/src/DllOpen.cpp  |   2 +-
 Code/Mantid/Framework/Kernel/src/Strings.cpp  |  16 +-
 .../Framework/Kernel/src/VectorHelper.cpp     |   6 +-
 .../LiveData/src/SNSLiveEventDataListener.cpp |   1 -
 .../Framework/MDAlgorithms/src/LoadSQW.cpp    |   8 +-
 .../MatlabAPI/src/MatlabInterface.cpp         |  43 +-
 Code/Mantid/Framework/SINQ/src/ProjectMD.cpp  |   3 +-
 .../MantidPlot/src/ApplicationWindow.cpp      |   1 -
 Code/Mantid/MantidPlot/src/PolynomialFit.cpp  |   2 +-
 .../MantidPlot/src/QwtErrorPlotCurve.cpp      |   6 +-
 Code/Mantid/MantidPlot/src/QwtPieCurve.cpp    |  14 +-
 .../MantidPlot/src/RangeSelectorTool.cpp      |  14 +-
 .../MantidPlot/src/RenameWindowDialog.cpp     |   2 +-
 Code/Mantid/MantidPlot/src/ScaleDraw.cpp      |   2 +-
 27 files changed, 267 insertions(+), 275 deletions(-)
 create mode 100644 Code/Mantid/Build/CMake/CppCheck_Suppressions.txt

diff --git a/Code/Mantid/Build/CMake/CppCheckSetup.cmake b/Code/Mantid/Build/CMake/CppCheckSetup.cmake
index 65915b14616..848c17d42ea 100644
--- a/Code/Mantid/Build/CMake/CppCheckSetup.cmake
+++ b/Code/Mantid/Build/CMake/CppCheckSetup.cmake
@@ -57,6 +57,8 @@ if ( CPPCHECK_EXECUTABLE )
         Framework/Kernel/src/Math/Optimization/SLSQPMinimizer.cpp
         MantidPlot/src/nrutil.cpp
         MantidPlot/src/origin/OPJFile.cpp
+        MantidPlot/src/zlib123/minigzip.c
+        Framework/SINQ/src/PoldiPeakFit.cpp
       )
 
   # Header files to be ignored require different handling
@@ -114,7 +116,7 @@ if ( CPPCHECK_EXECUTABLE )
   # put the finishing bits on the final command call
   set (_cppcheck_xml_args)
   if (CPPCHECK_GENERATE_XML)
-    list( APPEND _cppcheck_xml_args --xml --xml-version=2 ${_cppcheck_source_dirs} 2> ${CMAKE_BINARY_DIR}/cppcheck.xml )
+    list( APPEND _cppcheck_xml_args  --xml --xml-version=2 ${_cppcheck_source_dirs} 2> ${CMAKE_BINARY_DIR}/cppcheck.xml )
   else (CPPCHECK_GENERATE_XML)
     list( APPEND _cppcheck_xml_args  ${_cppcheck_source_dirs} )
   endif (CPPCHECK_GENERATE_XML)
diff --git a/Code/Mantid/Build/CMake/CppCheck_Suppressions.txt b/Code/Mantid/Build/CMake/CppCheck_Suppressions.txt
new file mode 100644
index 00000000000..540f4b3c079
--- /dev/null
+++ b/Code/Mantid/Build/CMake/CppCheck_Suppressions.txt
@@ -0,0 +1,11 @@
+// suppress memleak and exceptNew errors in the file src/file1.cpp
+//memleak:src/file1.cpp
+//exceptNew:src/file1.cpp
+
+// suppress in all files - BE CAREFULL not to leave trailing spaces after the rule id. or empty lines
+// This finds false positives where private member variable names reused by inheriting classes
+duplInheritedMember
+// For a library this is not a problem per se
+unusedFunction
+// cppcheck has problems handling the number of pre-processor definitions used in the DLL_EXPORTs
+class_X_Y
\ No newline at end of file
diff --git a/Code/Mantid/Build/CMake/FindCppcheck.cmake b/Code/Mantid/Build/CMake/FindCppcheck.cmake
index 4a5477428c6..7bb3a76d9bf 100644
--- a/Code/Mantid/Build/CMake/FindCppcheck.cmake
+++ b/Code/Mantid/Build/CMake/FindCppcheck.cmake
@@ -29,7 +29,7 @@ endif()
 find_program(CPPCHECK_EXECUTABLE NAMES cppcheck)
 
 if(MSVC)
-  set(CPPCHECK_TEMPLATE_ARG --template vs)
+  set(CPPCHECK_TEMPLATE_ARG --template "{file}({line}): warning : ({severity}-{id}) {message}")
   set(CPPCHECK_FAIL_REGULAR_EXPRESSION "[(]error[)]")
   set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]")
 elseif(CMAKE_COMPILER_IS_GNUCXX)
@@ -61,7 +61,7 @@ if(CPPCHECK_EXECUTABLE)
 endif()
 
 mark_as_advanced(CPPCHECK_EXECUTABLE)
-set ( CPPCHECK_ARGS --enable=all --inline-suppr CACHE STRING "Arguments for running cppcheck" )
+set ( CPPCHECK_ARGS --enable=all --inline-suppr CACHE STRING "Arguments for running cppcheck" --suppressions ${CMAKE_CURRENT_SOURCE_DIR}/Build/CMake/CppCheck_Suppressions.txt )
 set ( CPPCHECK_NUM_THREADS 0 CACHE STRING "Number of threads to use when running cppcheck" )
 set ( CPPCHECK_GENERATE_XML OFF CACHE BOOL "Generate xml output files from cppcheck" )
 
diff --git a/Code/Mantid/Framework/API/src/ParamFunction.cpp b/Code/Mantid/Framework/API/src/ParamFunction.cpp
index 830ada02824..f2793e5ae89 100644
--- a/Code/Mantid/Framework/API/src/ParamFunction.cpp
+++ b/Code/Mantid/Framework/API/src/ParamFunction.cpp
@@ -41,7 +41,7 @@ ParamFunction::~ParamFunction()
 void ParamFunction::setParameter(size_t i, const double& value, bool explicitlySet)
 {
   // Cppcheck confused by the check for NaN
-  // cppcheck-suppress duplicateExpression
+  
   if (boost::math::isnan(value))
   {
     // Check for NaN or -NaN
diff --git a/Code/Mantid/Framework/Algorithms/src/ConvertAxisByFormula.cpp b/Code/Mantid/Framework/Algorithms/src/ConvertAxisByFormula.cpp
index ebb98bd52f8..c53d7bbb3bf 100644
--- a/Code/Mantid/Framework/Algorithms/src/ConvertAxisByFormula.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/ConvertAxisByFormula.cpp
@@ -179,8 +179,6 @@ namespace Mantid
             MantidVec::iterator iter;
             for (iter = outputWs->dataX(0).begin(); iter != outputWs->dataX(0).end(); ++iter)
             {
-              // cppcheck cannot see that this is used by reference by muparser
-              // cppcheck-suppress unreadVariable
               axisValue = *iter;
               double result = p.Eval();
               *iter = result;
diff --git a/Code/Mantid/Framework/Algorithms/src/DetectorEfficiencyCorUser.cpp b/Code/Mantid/Framework/Algorithms/src/DetectorEfficiencyCorUser.cpp
index f9e4b2ac9f5..7ed79f37a81 100644
--- a/Code/Mantid/Framework/Algorithms/src/DetectorEfficiencyCorUser.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/DetectorEfficiencyCorUser.cpp
@@ -228,8 +228,7 @@ MantidVec DetectorEfficiencyCorUser::calculateEfficiency(double eff0,
 		for (; effOut_it != effOut.end(); ++xIn_it, ++effOut_it) {
 			if (conditionForEnergy ) {
         // cppcheck cannot see that this is used by reference by muparser
-        // cppcheck-suppress unreadVariable
-				e =  std::fabs(m_Ei + *xIn_it);
+        e =  std::fabs(m_Ei + *xIn_it);
 			}
 			else {
         // cppcheck cannot see that this is used by reference by muparser
diff --git a/Code/Mantid/Framework/Crystal/src/LoadIsawPeaks.cpp b/Code/Mantid/Framework/Crystal/src/LoadIsawPeaks.cpp
index f1bbd464228..addd4c871b1 100644
--- a/Code/Mantid/Framework/Crystal/src/LoadIsawPeaks.cpp
+++ b/Code/Mantid/Framework/Crystal/src/LoadIsawPeaks.cpp
@@ -106,12 +106,9 @@ namespace Crystal
 
       // Date: use the current date/time if not found
       Kernel::DateAndTime C_experimentDate;
-      std::string date;
       tag = getWord(in, false );
-      if(tag.empty())
-        date = Kernel::DateAndTime::getCurrentTime().toISO8601String();
-      else if(tag == "Date:")
-        date = getWord(in, false );
+      if(tag == "Date:")
+        getWord(in, false );
       readToEndOfLine( in, true );
       confidence = 95;
     }
diff --git a/Code/Mantid/Framework/Crystal/src/PredictFractionalPeaks.cpp b/Code/Mantid/Framework/Crystal/src/PredictFractionalPeaks.cpp
index 6030f214279..06cc4b435b6 100644
--- a/Code/Mantid/Framework/Crystal/src/PredictFractionalPeaks.cpp
+++ b/Code/Mantid/Framework/Crystal/src/PredictFractionalPeaks.cpp
@@ -11,22 +11,22 @@ when the new peaks are not created from a range of h ,k, and l values
 
 === Example usage ===
 
-     from mantidsimple import *
-     PeaksWrkSpace=mtd["PeaksQa"]
-             #Can be created via PredictPeaks( then do NOT use next line)
-     FindUBUsingFFT(PeaksWrkSpace,3,15,.12)
-     IndexPeaks(PeaksWrkSpace,.12,1)
-     PredictFractionalPeaks(PeaksWrkSpace,"FracPeaks","-.5,0,.5","-.5,.5","0")
-          #NOTE: There are editing options on PeaksWorkspaces, like combining 2 PeaksWorkspaces.
+from mantidsimple import *
+PeaksWrkSpace=mtd["PeaksQa"]
+#Can be created via PredictPeaks( then do NOT use next line)
+FindUBUsingFFT(PeaksWrkSpace,3,15,.12)
+IndexPeaks(PeaksWrkSpace,.12,1)
+PredictFractionalPeaks(PeaksWrkSpace,"FracPeaks","-.5,0,.5","-.5,.5","0")
+#NOTE: There are editing options on PeaksWorkspaces, like combining 2 PeaksWorkspaces.
 
 
- *WIKI*/
+*WIKI*/
 /*
- * PredictFractionalPeaks.cpp
- *
- *  Created on: Dec 5, 2012
- *      Author: ruth
- */
+* PredictFractionalPeaks.cpp
+*
+*  Created on: Dec 5, 2012
+*      Author: ruth
+*/
 #include "MantidCrystal/PredictFractionalPeaks.h"
 #include "MantidDataObjects/PeaksWorkspace.h"
 #include "MantidGeometry/Instrument.h"
@@ -65,7 +65,7 @@ namespace Mantid
 
 
     }
-        /// Sets documentation strings for this algorithm
+    /// Sets documentation strings for this algorithm
     void PredictFractionalPeaks::initDocs()
     {
       this->setWikiSummary("Creates a PeaksWorkspace with peaks occurring at specific fractional h,k,or l values");
@@ -76,10 +76,10 @@ namespace Mantid
     void PredictFractionalPeaks::init()
     {
       declareProperty(new WorkspaceProperty<PeaksWorkspace> ("Peaks", "", Direction::Input),
-                "Workspace of Peaks with orientation matrix that indexed the peaks and instrument loaded");
+        "Workspace of Peaks with orientation matrix that indexed the peaks and instrument loaded");
 
       declareProperty(new WorkspaceProperty<PeaksWorkspace> ("FracPeaks", "", Direction::Output),
-                "Workspace of Peaks with peaks with fractional h,k, and/or l values");
+        "Workspace of Peaks with peaks with fractional h,k, and/or l values");
 
       declareProperty(new Kernel::ArrayProperty<double>(string("HOffset"),string("-.5,0, .5")),"Offset in the h direction");
 
@@ -100,20 +100,20 @@ namespace Mantid
 
 
       setPropertySettings("Hmin",new Kernel::EnabledWhenProperty(string("IncludeAllPeaksInRange"),
-                                                         Kernel::IS_EQUAL_TO, "1"));
+        Kernel::IS_EQUAL_TO, "1"));
 
       setPropertySettings("Hmax",new Kernel::EnabledWhenProperty(string("IncludeAllPeaksInRange"),
-                                                           Kernel::IS_EQUAL_TO, "1"));
+        Kernel::IS_EQUAL_TO, "1"));
       setPropertySettings("Kmin",new Kernel::EnabledWhenProperty(string("IncludeAllPeaksInRange"),
-                                                             Kernel::IS_EQUAL_TO, "1"));
+        Kernel::IS_EQUAL_TO, "1"));
 
-       setPropertySettings("Kmax",new Kernel::EnabledWhenProperty(string("IncludeAllPeaksInRange"),
-                                                            Kernel::IS_EQUAL_TO, "1"));
+      setPropertySettings("Kmax",new Kernel::EnabledWhenProperty(string("IncludeAllPeaksInRange"),
+        Kernel::IS_EQUAL_TO, "1"));
       setPropertySettings("Lmin",new Kernel::EnabledWhenProperty(string("IncludeAllPeaksInRange"),
-                                                                 Kernel::IS_EQUAL_TO, "1"));
+        Kernel::IS_EQUAL_TO, "1"));
 
       setPropertySettings("Lmax",new Kernel::EnabledWhenProperty(string("IncludeAllPeaksInRange"),
-                                                                   Kernel::IS_EQUAL_TO, "1"));
+        Kernel::IS_EQUAL_TO, "1"));
 
 
     }
@@ -121,173 +121,169 @@ namespace Mantid
     /// Run the algorithm
     void PredictFractionalPeaks::exec()
     {
-       PeaksWorkspace_sptr Peaks=getProperty("Peaks");
-
-       vector<double> hOffsets = getProperty("HOffset");
-       vector<double> kOffsets = getProperty("KOffset");
-       vector<double> lOffsets = getProperty("LOffset");
-       if ( hOffsets.empty())hOffsets.push_back(0.0);
-       if ( kOffsets.empty())kOffsets.push_back(0.0);
-       if ( lOffsets.empty())lOffsets.push_back(0.0);
-
-;
-       bool includePeaksInRange= getProperty("IncludeAllPeaksInRange");
-
-       if(  Peaks->getNumberPeaks()<=0)
-       {
-         g_log.error()<<"There are No peaks in the input PeaksWorkspace\n";
-         return;
-       }
-
-       API::Sample samp= Peaks->sample();
-
-       Geometry::OrientedLattice &ol = samp.getOrientedLattice();
-
-       Geometry::Instrument_const_sptr Instr = Peaks->getInstrument();
-
-       boost::shared_ptr<IPeaksWorkspace> OutPeaks=WorkspaceFactory::Instance().createPeaks();
-       OutPeaks->setInstrument(Instr);
-
-       V3D hkl;
-       int peakNum =0;
-       int NPeaks = Peaks->getNumberPeaks();
-       Kernel::Matrix<double> Gon;
-       Gon.identityMatrix();
-
-       double Hmin= getProperty("Hmin");
-       double Hmax= getProperty("Hmax");
-       double Kmin= getProperty("Kmin");
-       double Kmax= getProperty("Kmax");
-       double Lmin= getProperty("Lmin");
-       double Lmax= getProperty("Lmax");
-
-       int N=NPeaks;
-       if( includePeaksInRange)
-       {
-         N=(int)((Hmax-Hmin+1)*(Kmax-Kmin+1)*(Lmax-Lmin+1)+.5);
-         N=max<int>(100,N);
-       }
-       IPeak& peak0 =Peaks->getPeak(0);
-       int RunNumber = peak0.getRunNumber();
-       Gon=peak0.getGoniometerMatrix();
-       Progress prog(this, 0,  1,N);
-       if( includePeaksInRange)
-       {
-
-
-         hkl[0]=Hmin;
-         hkl[1]=Kmin;
-         hkl[2]=Lmin;
-       }else
-       {
-         hkl[0]=peak0.getH();
-         hkl[1]=peak0.getK();
-         hkl[2] =peak0.getL();
-
-
-       }
-
-       Kernel::DblMatrix UB= ol.getUB();
-       vector< vector<int> > AlreadyDonePeaks;
-       bool done = false;
-       int ErrPos =1;//Used to determine position in code of a throw
-       while( !done)
-       {
-         for( size_t hoffset=0;hoffset<hOffsets.size();hoffset++)
-           for(size_t  koffset=0;koffset<kOffsets.size();koffset++)
-             for( size_t loffset=0;loffset<lOffsets.size();loffset++)
-                try
-                {
-                  V3D hkl1( hkl );
-                  ErrPos = 0;
-
-                  hkl1[0] += hOffsets[hoffset] ;
-                  hkl1[1] += kOffsets[koffset] ;
-                  hkl1[2] += lOffsets[loffset] ;
-
-                  Kernel::V3D Qs = UB * hkl1 ;
-                  Qs*= 2.0;
-                  Qs*=M_PI;
-                  Qs=Gon*Qs;
-                  if( Qs[2] <= 0 )
-                    continue;
-
-                  ErrPos=1;
-                  boost::shared_ptr<IPeak> peak( Peaks->createPeak( Qs, 1 ));
-
-                  peak->setGoniometerMatrix(Gon);
-
-                  if (Qs[2]>0 && peak->findDetector())
-                  {
-					// cppcheck-suppress redundantAssignment
-                    ErrPos=2;
-                    vector<int> SavPk;
-                    SavPk.push_back(RunNumber);
-                    SavPk.push_back((int)floor(1000*hkl1[0]+.5));
-                    SavPk.push_back((int)floor(1000*hkl1[1]+.5));
-                    SavPk.push_back((int)floor(1000*hkl1[2]+.5));
-
-                  //TODO keep list sorted so searching is faster?
-                    vector<vector<int> >::iterator it = find(AlreadyDonePeaks.begin(),AlreadyDonePeaks.end(),SavPk);
-
-					// cppcheck-suppress redundantAssignment
-                    ErrPos=3;
-                    if( it == AlreadyDonePeaks.end())
-                      AlreadyDonePeaks.push_back(SavPk);
-                    else
-                      continue;
-
-					// cppcheck-suppress redundantAssignment
-                    ErrPos=4;
-                    peak->setHKL(hkl1);
-                    peak->setRunNumber(RunNumber);
-                    OutPeaks->addPeak(*peak);
-                  }
-                }catch(...)
+      PeaksWorkspace_sptr Peaks=getProperty("Peaks");
+
+      vector<double> hOffsets = getProperty("HOffset");
+      vector<double> kOffsets = getProperty("KOffset");
+      vector<double> lOffsets = getProperty("LOffset");
+      if ( hOffsets.empty())hOffsets.push_back(0.0);
+      if ( kOffsets.empty())kOffsets.push_back(0.0);
+      if ( lOffsets.empty())lOffsets.push_back(0.0);
+
+      ;
+      bool includePeaksInRange= getProperty("IncludeAllPeaksInRange");
+
+      if(  Peaks->getNumberPeaks()<=0)
+      {
+        g_log.error()<<"There are No peaks in the input PeaksWorkspace\n";
+        return;
+      }
+
+      API::Sample samp= Peaks->sample();
+
+      Geometry::OrientedLattice &ol = samp.getOrientedLattice();
+
+      Geometry::Instrument_const_sptr Instr = Peaks->getInstrument();
+
+      boost::shared_ptr<IPeaksWorkspace> OutPeaks=WorkspaceFactory::Instance().createPeaks();
+      OutPeaks->setInstrument(Instr);
+
+      V3D hkl;
+      int peakNum =0;
+      int NPeaks = Peaks->getNumberPeaks();
+      Kernel::Matrix<double> Gon;
+      Gon.identityMatrix();
+
+      double Hmin= getProperty("Hmin");
+      double Hmax= getProperty("Hmax");
+      double Kmin= getProperty("Kmin");
+      double Kmax= getProperty("Kmax");
+      double Lmin= getProperty("Lmin");
+      double Lmax= getProperty("Lmax");
+
+      int N=NPeaks;
+      if( includePeaksInRange)
+      {
+        N=(int)((Hmax-Hmin+1)*(Kmax-Kmin+1)*(Lmax-Lmin+1)+.5);
+        N=max<int>(100,N);
+      }
+      IPeak& peak0 =Peaks->getPeak(0);
+      int RunNumber = peak0.getRunNumber();
+      Gon=peak0.getGoniometerMatrix();
+      Progress prog(this, 0,  1,N);
+      if( includePeaksInRange)
+      {
+
+
+        hkl[0]=Hmin;
+        hkl[1]=Kmin;
+        hkl[2]=Lmin;
+      }else
+      {
+        hkl[0]=peak0.getH();
+        hkl[1]=peak0.getK();
+        hkl[2] =peak0.getL();
+
+
+      }
+
+      Kernel::DblMatrix UB= ol.getUB();
+      vector< vector<int> > AlreadyDonePeaks;
+      bool done = false;
+      int ErrPos =1;//Used to determine position in code of a throw
+      while( !done)
+      {
+        for( size_t hoffset=0;hoffset<hOffsets.size();hoffset++)
+          for(size_t  koffset=0;koffset<kOffsets.size();koffset++)
+            for( size_t loffset=0;loffset<lOffsets.size();loffset++)
+              try
+            {
+              V3D hkl1( hkl );
+              ErrPos = 0;
+
+              hkl1[0] += hOffsets[hoffset] ;
+              hkl1[1] += kOffsets[koffset] ;
+              hkl1[2] += lOffsets[loffset] ;
+
+              Kernel::V3D Qs = UB * hkl1 ;
+              Qs*= 2.0;
+              Qs*=M_PI;
+              Qs=Gon*Qs;
+              if( Qs[2] <= 0 )
+                continue;
+
+              ErrPos=1;
+
+              boost::shared_ptr<IPeak> peak( Peaks->createPeak( Qs, 1 ));
+
+              peak->setGoniometerMatrix(Gon);
+
+              if (Qs[2]>0 && peak->findDetector())
+              {
+                ErrPos=2;
+                vector<int> SavPk;
+                SavPk.push_back(RunNumber);
+                SavPk.push_back((int)floor(1000*hkl1[0]+.5));
+                SavPk.push_back((int)floor(1000*hkl1[1]+.5));
+                SavPk.push_back((int)floor(1000*hkl1[2]+.5));
+
+                //TODO keep list sorted so searching is faster?
+                vector<vector<int> >::iterator it = find(AlreadyDonePeaks.begin(),AlreadyDonePeaks.end(),SavPk);
+
+
+                if( it == AlreadyDonePeaks.end())
+                  AlreadyDonePeaks.push_back(SavPk);
+                else
+                  continue;
+
+                peak->setHKL(hkl1);
+                peak->setRunNumber(RunNumber);
+                OutPeaks->addPeak(*peak);
+              }
+            }catch(...)
+            {
+              if( ErrPos != 1)// setQLabFrame in createPeak throws exception
+                throw new std::invalid_argument( "Invalid data at this point");
+            }
+            if( includePeaksInRange)
+            {
+              hkl[0]++;
+              if( hkl[0]>Hmax)
+              {
+                hkl[0]=Hmin;
+                hkl[1]++;
+                if( hkl[1]> Kmax)
                 {
 
-                  if( ErrPos != 1)// setQLabFrame in createPeak throws exception
-                    throw new std::invalid_argument( "Invalid data at this point");
+                  hkl[1]=Kmin;
+                  hkl[2]++;
+                  if( hkl[2]> Lmax)
+                    done = true;
                 }
-         if( includePeaksInRange)
-         {
-           hkl[0]++;
-           if( hkl[0]>Hmax)
-           {
-             hkl[0]=Hmin;
-             hkl[1]++;
-             if( hkl[1]> Kmax)
-             {
-
-               hkl[1]=Kmin;
-               hkl[2]++;
-               if( hkl[2]> Lmax)
-                 done = true;
-             }
-           }
-         }else
-         {
-           peakNum++;
-           if( peakNum >= NPeaks)
-             done = true;
-           else
-           {// peak0= Peaks->getPeak(peakNum);
-             IPeak& peak1= Peaks->getPeak(peakNum);
-           //??? could not assign to peak0 above. Did not work
-            // the peak that peak0 was associated with did NOT change
-             hkl[0]=peak1.getH();
-             hkl[1]=peak1.getK();
-             hkl[2] =peak1.getL();
-             Gon=peak1.getGoniometerMatrix();
-             RunNumber = peak1.getRunNumber();
-
-           }
-         }
-         prog.report();
-       }
-
-
-     setProperty("FracPeaks",OutPeaks);
+              }
+            }else
+            {
+              peakNum++;
+              if( peakNum >= NPeaks)
+                done = true;
+              else
+              {// peak0= Peaks->getPeak(peakNum);
+                IPeak& peak1= Peaks->getPeak(peakNum);
+                //??? could not assign to peak0 above. Did not work
+                // the peak that peak0 was associated with did NOT change
+                hkl[0]=peak1.getH();
+                hkl[1]=peak1.getK();
+                hkl[2] =peak1.getL();
+                Gon=peak1.getGoniometerMatrix();
+                RunNumber = peak1.getRunNumber();
+
+              }
+            }
+            prog.report();
+      }
+
+
+      setProperty("FracPeaks",OutPeaks);
 
 
 
@@ -295,4 +291,4 @@ namespace Mantid
 
 
   }//namespace Crystal
-  }//namespace Mantid
+}//namespace Mantid
diff --git a/Code/Mantid/Framework/CurveFitting/src/ReflectivityMulf.cpp b/Code/Mantid/Framework/CurveFitting/src/ReflectivityMulf.cpp
index cdbf561c471..583158f550f 100644
--- a/Code/Mantid/Framework/CurveFitting/src/ReflectivityMulf.cpp
+++ b/Code/Mantid/Framework/CurveFitting/src/ReflectivityMulf.cpp
@@ -275,13 +275,6 @@ namespace CurveFitting
           coeff[8+i*3] = 0.0;
           coeff[9+i*3] = 0.0;
         }
-      }else if(m_nlayer < m_nlayer_old){
-        for (int i = 0; i < m_nlayer; ++i)
-        {
-          coeff[7+i*3] = getParameter(7+i*3);
-          coeff[8+i*3] = getParameter(8+i*3);
-          coeff[9+i*3] = getParameter(9+i*3);
-        }
       }else {
         for (int i = 0; i < m_nlayer; ++i)
         {
diff --git a/Code/Mantid/Framework/DataHandling/src/FindDetectorsPar.cpp b/Code/Mantid/Framework/DataHandling/src/FindDetectorsPar.cpp
index ce31c1ee96e..f3df83090b7 100644
--- a/Code/Mantid/Framework/DataHandling/src/FindDetectorsPar.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/FindDetectorsPar.cpp
@@ -608,7 +608,6 @@ FindDetectorsPar::get_ASCII_header(std::string const &fileName, std::ifstream &d
     int space_to_symbol_change=count_changes(&BUF[0],BUF.size());
     if(space_to_symbol_change>1){  // more then one group of symbols in the string, spe file
         int nData_records(0),nData_blocks(0);
-        // cppcheck-suppress invalidscanf
         int nDatas = sscanf(&BUF[0]," %d %d ",&nData_records,&nData_blocks);
         file_descriptor.nData_records = (size_t)nData_records;
         file_descriptor.nData_blocks  = (size_t)nData_blocks;
diff --git a/Code/Mantid/Framework/DataHandling/src/SaveCanSAS1D.cpp b/Code/Mantid/Framework/DataHandling/src/SaveCanSAS1D.cpp
index 17ceb4c2008..98c9bfd9b22 100644
--- a/Code/Mantid/Framework/DataHandling/src/SaveCanSAS1D.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/SaveCanSAS1D.cpp
@@ -255,12 +255,12 @@ bool SaveCanSAS1D::openForAppending(const std::string & filename)
  */
 void SaveCanSAS1D::findEndofLastEntry()
 {
-  static const int LAST_TAG_LEN = 11;
-
   const int rootTagLen = static_cast<int>(std::string("</SASroot>").length());
 
   try
   {
+    static const int LAST_TAG_LEN = 11;
+
     //move to the place _near_ the end of the file where the data will be appended to
     m_outFile.seekg(-LAST_TAG_LEN-rootTagLen, std::ios::end);
     char test_tag[LAST_TAG_LEN+1];
diff --git a/Code/Mantid/Framework/Geometry/src/Math/ORourkeIntersection.cpp b/Code/Mantid/Framework/Geometry/src/Math/ORourkeIntersection.cpp
index c9355b38e22..4151c86a610 100644
--- a/Code/Mantid/Framework/Geometry/src/Math/ORourkeIntersection.cpp
+++ b/Code/Mantid/Framework/Geometry/src/Math/ORourkeIntersection.cpp
@@ -51,7 +51,6 @@ namespace Mantid
       const size_t nverts_p(P.numVertices()), nverts_q(Q.numVertices());
       const V2D origin(0.0,0.0);
 
-      size_t pi(0), pim1(0), qi(0), qim1(0);
       size_t count_p(0), count_q(0); // Number of vertices visited
       unsigned int inflag(Unknown);
       bool firstPoint(true);
@@ -65,6 +64,8 @@ namespace Mantid
       Vertex2DList intersectList;
       do
       {
+        size_t pi(0), pim1(0), qi(0), qim1(0);
+      
         // Compute a vector between the previous point in the direction of the next
         pim1 = (pi + nverts_p - 1) % nverts_p;
         qim1 = (qi + nverts_q - 1) % nverts_q;
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/Strings.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/Strings.h
index a80b0c16458..bba48a111ce 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/Strings.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/Strings.h
@@ -108,7 +108,7 @@ namespace Mantid
       template<typename T> int convert(const char* A,T& out);
 
       /// Convert a number to a string
-      template<typename T> std::string toString(const T value);
+      template<typename T> std::string toString(const T &value);
 
       /// Convert a vector to a string
       template<typename T> std::string toString(const std::vector<T> &value);
diff --git a/Code/Mantid/Framework/Kernel/src/DllOpen.cpp b/Code/Mantid/Framework/Kernel/src/DllOpen.cpp
index d60de632d77..219fd38927a 100644
--- a/Code/Mantid/Framework/Kernel/src/DllOpen.cpp
+++ b/Code/Mantid/Framework/Kernel/src/DllOpen.cpp
@@ -155,7 +155,7 @@ void* DllOpen::OpenDllImpl(const std::string& filePath)
     //          LocalSize(lpDisplayBuf) / sizeof(TCHAR),
     //          TEXT("failed with error %d: %s"), 
     //          dw, lpMsgBuf); 
-    _snprintf((char*)lpDisplayBuf, n, "failed with error %d: %s", dw, lpMsgBuf);
+    _snprintf((char*)lpDisplayBuf, n, "failed with error %lu: %s", dw, lpMsgBuf);
     log.error()<<"Could not open library " << filePath << ": " << (LPCTSTR)lpDisplayBuf << std::endl;
 
     LocalFree(lpMsgBuf);
diff --git a/Code/Mantid/Framework/Kernel/src/Strings.cpp b/Code/Mantid/Framework/Kernel/src/Strings.cpp
index 13d7333e79a..2455fdbdba0 100644
--- a/Code/Mantid/Framework/Kernel/src/Strings.cpp
+++ b/Code/Mantid/Framework/Kernel/src/Strings.cpp
@@ -707,7 +707,7 @@ namespace Mantid
        * @return a string
        */
       template<typename T>
-      std::string toString(const T value)
+      std::string toString(const T &value)
       {
         std::ostringstream mess;
         mess << value;
@@ -1153,15 +1153,15 @@ namespace Mantid
       template MANTID_KERNEL_DLL int convert(const char*,int&);
       template MANTID_KERNEL_DLL int convert(const char*,std::size_t&);
 
-      template MANTID_KERNEL_DLL std::string toString(const double value);
-      template MANTID_KERNEL_DLL std::string toString(const float value);
-      template MANTID_KERNEL_DLL std::string toString(const int value);
-      template MANTID_KERNEL_DLL std::string toString(const uint16_t value);
-      template MANTID_KERNEL_DLL std::string toString(const size_t value); // Matches uint64_t on Linux 64 & Win 64
+      template MANTID_KERNEL_DLL std::string toString(const double &value);
+      template MANTID_KERNEL_DLL std::string toString(const float &value);
+      template MANTID_KERNEL_DLL std::string toString(const int &value);
+      template MANTID_KERNEL_DLL std::string toString(const uint16_t &value);
+      template MANTID_KERNEL_DLL std::string toString(const size_t &value); // Matches uint64_t on Linux 64 & Win 64
 #if defined(__APPLE__) || ( defined(_WIN32) && !defined(_WIN64)) || (defined(__GNUC__) && !defined(__LP64__)) // Mac or 32-bit compiler
-      template MANTID_KERNEL_DLL std::string toString(const uint64_t value);
+      template MANTID_KERNEL_DLL std::string toString(const uint64_t &value);
 #endif
-      template MANTID_KERNEL_DLL std::string toString(const std::string value);
+      template MANTID_KERNEL_DLL std::string toString(const std::string &value);
 
       template MANTID_KERNEL_DLL std::string toString(const std::vector<int> &value);
 
diff --git a/Code/Mantid/Framework/Kernel/src/VectorHelper.cpp b/Code/Mantid/Framework/Kernel/src/VectorHelper.cpp
index 4d87b05a376..00b4ce2443b 100644
--- a/Code/Mantid/Framework/Kernel/src/VectorHelper.cpp
+++ b/Code/Mantid/Framework/Kernel/src/VectorHelper.cpp
@@ -257,12 +257,12 @@ void rebinHistogram(const std::vector<double>& xold, const std::vector<double>&
   
   double frac, fracE;
   double oneOverWidth, overlap;
-  double temp, xold_of_iold, xold_of_iold_p_1;
+  double temp;
 
   //loop over old vector from starting point calculated above
   for ( ; iold<size_yold; ++iold )
   {
-    xold_of_iold_p_1 = xold[iold+1]; // cache for speed
+    double xold_of_iold_p_1 = xold[iold+1]; // cache for speed
     // If current old bin is fully enclosed by new bin, just unload the counts
     if ( xold_of_iold_p_1 <= xnew[inew+1] )
     {
@@ -274,7 +274,7 @@ void rebinHistogram(const std::vector<double>& xold, const std::vector<double>&
     }
     else
     {
-      xold_of_iold = xold[iold]; // cache for speed
+      double xold_of_iold = xold[iold]; // cache for speed
       // This is the counts per unit X in current old bin
       oneOverWidth = 1. / (xold_of_iold_p_1 - xold_of_iold); // cache 1/width to speed things up
       frac = yold[iold] * oneOverWidth;
diff --git a/Code/Mantid/Framework/LiveData/src/SNSLiveEventDataListener.cpp b/Code/Mantid/Framework/LiveData/src/SNSLiveEventDataListener.cpp
index 97a247e92e9..82d2cc1b03f 100644
--- a/Code/Mantid/Framework/LiveData/src/SNSLiveEventDataListener.cpp
+++ b/Code/Mantid/Framework/LiveData/src/SNSLiveEventDataListener.cpp
@@ -212,7 +212,6 @@ namespace LiveData
     if (m_isConnected == false) // sanity check
     {
       throw std::runtime_error( std::string("SNSLiveEventDataListener::run(): No connection to SMS server."));
-      return;  // should never be called, but here just in case exceptions are disabled
     }
 
     // First thing to do is send a hello packet
diff --git a/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp b/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp
index 2b5c048b9e6..fe1f61c8128 100644
--- a/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp
+++ b/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp
@@ -887,8 +887,6 @@ namespace LoadSQWHelper
    { // we do not need this header  at the moment -> just calculating its length; or may be we do soon?
       std::vector<char> data_buffer(8);
 
-      // cppcheck-suppress redundantAssignment
-      std::streamoff end_location = start_location;
       std::streamoff shift = start_location-dataStream.tellg();
       // move to specified location, which should be usually 0;
       dataStream.seekg(shift,std::ios_base::cur);
@@ -932,7 +930,7 @@ namespace LoadSQWHelper
       // skip labels
       dataStream.seekg(nRows*nCols,std::ios_base::cur);
 
-      end_location = dataStream.tellg();
+      std::streamoff end_location = dataStream.tellg();
       return end_location;
 
     }
@@ -945,8 +943,6 @@ namespace LoadSQWHelper
     { //
       std::vector<char> data_buffer(8);
 
-      // cppcheck-suppress redundantAssignment
-      std::streamoff end_location = start_location;
       std::streamoff shift = start_location-dataStream.tellg();
       // move to specified location, which should be usually 0;
       dataStream.seekg(shift,std::ios_base::cur);              
@@ -967,7 +963,7 @@ namespace LoadSQWHelper
       //skip detector information
       dataStream.seekg(num_detectors*6*4,std::ios_base::cur);  
 
-      end_location = dataStream.tellg();
+      std::streamoff end_location = dataStream.tellg();
       return end_location;
 
     }
diff --git a/Code/Mantid/Framework/MatlabAPI/src/MatlabInterface.cpp b/Code/Mantid/Framework/MatlabAPI/src/MatlabInterface.cpp
index d3c7d7815cc..9e1dd3f04c3 100644
--- a/Code/Mantid/Framework/MatlabAPI/src/MatlabInterface.cpp
+++ b/Code/Mantid/Framework/MatlabAPI/src/MatlabInterface.cpp
@@ -158,7 +158,7 @@ static void unrollCell(const mxArray *prhs, const mxArray* new_prhs[], int& new_
   */
 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray* prhs[])
 {
-	int i, n, nrhs_2, func_called = 0, errcode = 0;
+	int i, nrhs_2, func_called = 0, errcode = 0;
 	static int first_call = 0;
 	static int call_depth = 0;
 	char error_buffer[256];
@@ -203,7 +203,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray* prhs[])
 	if (!compare_nocase(funcname + (i - 9), "_varargin"))
 	{
 		funcname[i-9] = '\0';	/* remove the trailing "_varargin" from the name */
-		n = 0;
+		int n = 0;
 		for(i=0; i<nrhs; i++)
 		{
 			unrollCell(prhs[i], new_prhs, n);
@@ -386,15 +386,16 @@ int DeleteWorkspace(int nlhs, mxArray *plhs[], int nrhs, const mxArray* prhs[])
    */
 int CreateAlgorithm(int nlhs, mxArray *plhs[], int nrhs, const mxArray* prhs[])
 {
-	mwSize dims[2] = { 1, 1 };
-    char algName[128];
 	try
 	{
-	    mxGetString(prhs[0], algName, sizeof(algName));
-	    IAlgorithm* alg = FrameworkManager::Instance().createAlgorithm(algName);
-	    plhs[0] = mxCreateNumericArray(2, dims, mxUINT64_CLASS, mxREAL);
-	    uint64_t* data = (uint64_t*)mxGetData(plhs[0]);
-	    data[0] = (uint64_t)alg;
+    char algName[128];
+    mwSize dims[2] = { 1, 1 };
+
+	  mxGetString(prhs[0], algName, sizeof(algName));
+	  IAlgorithm* alg = FrameworkManager::Instance().createAlgorithm(algName);
+	  plhs[0] = mxCreateNumericArray(2, dims, mxUINT64_CLASS, mxREAL);
+	  uint64_t* data = (uint64_t*)mxGetData(plhs[0]);
+	  data[0] = (uint64_t)alg;
 		return 0;
 	}
 	catch(std::exception& e)
@@ -414,16 +415,17 @@ int CreateAlgorithm(int nlhs, mxArray *plhs[], int nrhs, const mxArray* prhs[])
    */
 int RunAlgorithm(int nlhs, mxArray *plhs[], int nrhs, const mxArray* prhs[])
 {
-	char buffer[256];
 	try
 	{
-	    uint64_t* data = (uint64_t*)mxGetData(prhs[0]);
-	    IAlgorithm* alg = (IAlgorithm*)data[0];
-      mxGetString(prhs[1], buffer, sizeof(buffer));
-      alg->setProperties(buffer);
-	    alg->execute();
-	    plhs[0] = mxCreateString("");
-	    return 0;
+    char buffer[256];
+	
+	  uint64_t* data = (uint64_t*)mxGetData(prhs[0]);
+	  IAlgorithm* alg = (IAlgorithm*)data[0];
+    mxGetString(prhs[1], buffer, sizeof(buffer));
+    alg->setProperties(buffer);
+	  alg->execute();
+	  plhs[0] = mxCreateString("");
+	  return 0;
 	}
 	catch(std::exception& e)
 	{
@@ -443,11 +445,12 @@ int RunAlgorithm(int nlhs, mxArray *plhs[], int nrhs, const mxArray* prhs[])
   */
 int RunAlgorithmPV(int nlhs, mxArray *plhs[], int nrhs, const mxArray* prhs[])
 {
-	char buffer[256];
-	mxArray* marray;
-	std::string property_name;
 	try
 	{
+	    mxArray* marray;	
+      char buffer[256];
+	    std::string property_name;
+
 	    uint64_t* data = (uint64_t*)mxGetData(prhs[0]);
 	    IAlgorithm* alg = (IAlgorithm*)data[0];
 	    int i=1;
diff --git a/Code/Mantid/Framework/SINQ/src/ProjectMD.cpp b/Code/Mantid/Framework/SINQ/src/ProjectMD.cpp
index e6981ce0b09..3650053df0b 100644
--- a/Code/Mantid/Framework/SINQ/src/ProjectMD.cpp
+++ b/Code/Mantid/Framework/SINQ/src/ProjectMD.cpp
@@ -172,7 +172,6 @@ void ProjectMD::putValue(IMDHistoWorkspace_sptr ws, int dim[], double value)
 void ProjectMD::sumData(IMDHistoWorkspace_sptr inWS, IMDHistoWorkspace_sptr outWS,
 		  int *sourceDim, int *targetDim, int targetDimCount, int dimNo, int start, int end, int currentDim)
 {
-	  double sumVal = 0;
 	  boost::shared_ptr<const IMDDimension> dimi;
 
 	  /*
@@ -181,7 +180,7 @@ void ProjectMD::sumData(IMDHistoWorkspace_sptr inWS, IMDHistoWorkspace_sptr outW
 	   */
 	  if (currentDim == static_cast<int>(inWS->getNumDims())) {
 	    int length = end - start;
-	    sumVal = getValue(outWS, targetDim);
+	    double sumVal = getValue(outWS, targetDim);
 	    for (int i = 0; i < length; i++) {
 	      sourceDim[dimNo] = start + i;
 	      double val = getValue(inWS, sourceDim);
diff --git a/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp b/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
index f3669640c7b..78a7c92aaf4 100644
--- a/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
+++ b/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
@@ -6326,7 +6326,6 @@ bool ApplicationWindow::setWindowName(MdiSubWindow *w, const QString &text)
 
   newName.replace("_", "-");
 
-  // cppcheck-suppress uninitvar
   while(alreadyUsedName(newName)){
     QMessageBox::critical(this, tr("MantidPlot - Error"), tr("Name <b>%1</b> already exists!").arg(newName)+//Mantid
         "<p>"+tr("Please choose another name!")+
diff --git a/Code/Mantid/MantidPlot/src/PolynomialFit.cpp b/Code/Mantid/MantidPlot/src/PolynomialFit.cpp
index d9536c7fa5f..c21ca1f7516 100644
--- a/Code/Mantid/MantidPlot/src/PolynomialFit.cpp
+++ b/Code/Mantid/MantidPlot/src/PolynomialFit.cpp
@@ -289,7 +289,7 @@ void LinearFit::fit()
 
 	generateFitCurve();
 
-	ApplicationWindow *app = (ApplicationWindow *)parent();
+	ApplicationWindow *app = static_cast<ApplicationWindow *>(parent());
 	if (app->writeFitResultsToLog)
 		app->updateLog(logFitInfo(0, 0));
 }
diff --git a/Code/Mantid/MantidPlot/src/QwtErrorPlotCurve.cpp b/Code/Mantid/MantidPlot/src/QwtErrorPlotCurve.cpp
index 4eea7b2e241..fa46d3457e5 100644
--- a/Code/Mantid/MantidPlot/src/QwtErrorPlotCurve.cpp
+++ b/Code/Mantid/MantidPlot/src/QwtErrorPlotCurve.cpp
@@ -90,9 +90,9 @@ void QwtErrorPlotCurve::drawErrorBars(QPainter *painter, const QwtScaleMap &xMap
   double d_xOffset = 0.0;
   double d_yOffset = 0.0;
   if (d_master_curve->type() == Graph::VerticalBars)
-    d_xOffset = ((QwtBarCurve *) d_master_curve)->dataOffset();
+    d_xOffset = (static_cast<QwtBarCurve *>(d_master_curve))->dataOffset();
   else if (d_master_curve->type() == Graph::HorizontalBars)
-    d_yOffset = ((QwtBarCurve *) d_master_curve)->dataOffset();
+    d_yOffset = (static_cast<QwtBarCurve *>(d_master_curve))->dataOffset();
 
   int skipPoints = d_master_curve->skipSymbolsCount();
 
@@ -272,7 +272,7 @@ void QwtErrorPlotCurve::loadData()
   int r = abs(d_end_row - d_start_row) + 1;
   QVector<double> X(r), Y(r), err(r);
   int data_size = 0;
-  QLocale locale = ((Plot *) plot())->locale();
+  QLocale locale = (static_cast<Plot *>(plot()))->locale();
   for (int i = d_start_row; i <= d_end_row; i++)
   {
     QString xval = mt->text(i, xcol);
diff --git a/Code/Mantid/MantidPlot/src/QwtPieCurve.cpp b/Code/Mantid/MantidPlot/src/QwtPieCurve.cpp
index 5ad62626b18..88a441c0b7c 100644
--- a/Code/Mantid/MantidPlot/src/QwtPieCurve.cpp
+++ b/Code/Mantid/MantidPlot/src/QwtPieCurve.cpp
@@ -141,9 +141,9 @@ void QwtPieCurve::drawDisk(QPainter *painter, const QwtScaleMap &xMap, const Qwt
           s += QString::number(d_table_rows[0]) + "\n";
 
         if (d_values && d_percentages)
-          s += ((Plot *)plot())->locale().toString(y(0), 'g', 4) + " (100%)";
+          s += (static_cast<Plot *>(plot()))->locale().toString(y(0), 'g', 4) + " (100%)";
         else if (d_values)
-          s += ((Plot *)plot())->locale().toString(y(0), 'g', 4);
+          s += (static_cast<Plot *>(plot()))->locale().toString(y(0), 'g', 4);
         else if (d_percentages)
           s += "100%";
         l->setText(s);
@@ -222,7 +222,7 @@ void QwtPieCurve::drawSlices(QPainter *painter, const QwtScaleMap &xMap, const Q
 
   painter->save();
 
-  QLocale locale = ((Plot *)plot())->locale();
+  QLocale locale = (static_cast<Plot *>(plot()))->locale();
   for (int i = from; i <= to; i++){
     const double yi = y(i);
     const double q = yi/sum;
@@ -373,7 +373,7 @@ void QwtPieCurve::loadData()
     d_end_row = d_start_row + 1000;
   }
 
-  Plot *d_plot = (Plot *)plot();
+  Plot *d_plot = static_cast<Plot *>(plot());
   QLocale locale = d_plot->locale();
   QVarLengthArray<double> X(abs(d_end_row - d_start_row) + 1);
   d_table_rows.resize(abs(d_end_row - d_start_row) + 1);
@@ -414,7 +414,7 @@ void QwtPieCurve::addLabel(PieLabel *l, bool clone)
     return;
 
   if (clone){
-    PieLabel *newLabel = new PieLabel((Plot *)plot(), this);
+    PieLabel *newLabel = new PieLabel(static_cast<Plot *>(plot()), this);
     newLabel->clone(l);
     newLabel->setCustomText(l->customText());
     d_texts_list << newLabel;
@@ -433,7 +433,7 @@ void QwtPieCurve::removeLabel(PieLabel *l)
   if (index < 0 || index >= d_texts_list.size())
     return;
 
-  PieLabel *newLabel = new PieLabel((Plot *)plot(), this);
+  PieLabel *newLabel = new PieLabel(static_cast<Plot *>(plot()), this);
   newLabel->clone(l);
   newLabel->setCustomText(l->customText());
   newLabel->hide();
@@ -450,7 +450,7 @@ void QwtPieCurve::initLabels()
   for (int i = 0; i < dataPoints; i++)
     sum += y(i);
 
-  Plot *d_plot = (Plot *)plot();
+  Plot *d_plot = static_cast<Plot *>(plot());
   QLocale locale = d_plot->locale();
   for (int i = 0; i <size; i++ ){
     PieLabel* l = new PieLabel(d_plot, this);
diff --git a/Code/Mantid/MantidPlot/src/RangeSelectorTool.cpp b/Code/Mantid/MantidPlot/src/RangeSelectorTool.cpp
index 013a42fe40e..96919116cda 100644
--- a/Code/Mantid/MantidPlot/src/RangeSelectorTool.cpp
+++ b/Code/Mantid/MantidPlot/src/RangeSelectorTool.cpp
@@ -105,7 +105,7 @@ void RangeSelectorTool::pointSelected(const QPoint &pos)
 	const int curve_key = d_graph->plotWidget()->closestCurve(pos.x(), pos.y(), dist, point);
 	if (curve_key < 0 || dist >= 5) // 5 pixels tolerance
 		return;
-	QwtPlotCurve *curve = (QwtPlotCurve *)d_graph->plotWidget()->curve(curve_key);
+	QwtPlotCurve *curve = static_cast<QwtPlotCurve *>(d_graph->plotWidget()->curve(curve_key));
 	if (!curve)
 		return;
 
@@ -151,7 +151,7 @@ void RangeSelectorTool::setActivePoint(int point)
 void RangeSelectorTool::emitStatusText()
 {
     QLocale locale = d_graph->plotWidget()->locale();
-    if (((PlotCurve *)d_selected_curve)->type() == Graph::Function){
+    if ((static_cast<PlotCurve *>(d_selected_curve))->type() == Graph::Function){
          emit statusText(QString("%1 <=> %2[%3]: x=%4; y=%5")
 			.arg(d_active_marker.xValue() > d_inactive_marker.xValue() ? tr("Right") : tr("Left"))
 			.arg(d_selected_curve->title().text())
@@ -159,17 +159,17 @@ void RangeSelectorTool::emitStatusText()
 			.arg(locale.toString(d_selected_curve->x(d_active_point), 'G', 16))
 			.arg(locale.toString(d_selected_curve->y(d_active_point), 'G', 16)));
     } else {
-        Table *t = ((DataCurve*)d_selected_curve)->table();
+        Table *t = (static_cast<DataCurve*>(d_selected_curve))->table();
         if (!t)
             return;
 
-        int row = ((DataCurve*)d_selected_curve)->tableRow(d_active_point);
+        int row = (static_cast<DataCurve*>(d_selected_curve))->tableRow(d_active_point);
 
         emit statusText(QString("%1 <=> %2[%3]: x=%4; y=%5")
 			.arg(d_active_marker.xValue() > d_inactive_marker.xValue() ? tr("Right") : tr("Left"))
 			.arg(d_selected_curve->title().text())
 			.arg(row + 1)
-			.arg(t->text(row, t->colIndex(((DataCurve*)d_selected_curve)->xColumnName())))
+			.arg(t->text(row, t->colIndex((static_cast<DataCurve*>(d_selected_curve))->xColumnName())))
 			.arg(t->text(row, t->colIndex(d_selected_curve->title().text()))));
     }
 }
@@ -391,8 +391,8 @@ void RangeSelectorTool::setCurveRange()
     if (!d_selected_curve)
         return;
 
-    if (((PlotCurve *)d_selected_curve)->type() != Graph::Function){
-        ((DataCurve*)d_selected_curve)->setRowRange(QMIN(d_active_point, d_inactive_point),
+    if ((static_cast<PlotCurve *>(d_selected_curve))->type() != Graph::Function){
+        (static_cast<DataCurve*>(d_selected_curve))->setRowRange(QMIN(d_active_point, d_inactive_point),
                                     QMAX(d_active_point, d_inactive_point));
         d_graph->updatePlot();
         d_graph->notifyChanges();
diff --git a/Code/Mantid/MantidPlot/src/RenameWindowDialog.cpp b/Code/Mantid/MantidPlot/src/RenameWindowDialog.cpp
index 2e8e43ee2c3..4f70fe9fab2 100644
--- a/Code/Mantid/MantidPlot/src/RenameWindowDialog.cpp
+++ b/Code/Mantid/MantidPlot/src/RenameWindowDialog.cpp
@@ -134,7 +134,7 @@ void RenameWindowDialog::accept()
 	if (text == name && label == window->windowLabel() && window->captionPolicy() == policy)
 		close();
 
-	ApplicationWindow *app = (ApplicationWindow *)parentWidget();
+	ApplicationWindow *app = static_cast<ApplicationWindow *>(parentWidget());
 	if (!app)
 		return;
 
diff --git a/Code/Mantid/MantidPlot/src/ScaleDraw.cpp b/Code/Mantid/MantidPlot/src/ScaleDraw.cpp
index d8694351f4a..85d2926491c 100644
--- a/Code/Mantid/MantidPlot/src/ScaleDraw.cpp
+++ b/Code/Mantid/MantidPlot/src/ScaleDraw.cpp
@@ -100,7 +100,7 @@ QwtText ScaleDraw::label(double value) const
 	switch (d_type){
 		case Numeric:
 		{
-            QLocale locale = ((Graph *)d_plot->parent())->multiLayer()->locale();
+            QLocale locale = (static_cast<Graph *>(d_plot->parent()))->multiLayer()->locale();
 			if (d_numeric_format == Superscripts){
 				QString txt = locale.toString(transformValue(value), 'e', d_prec);
 				QStringList list = txt.split("e", QString::SkipEmptyParts);
-- 
GitLab