Skip to content

Commit

Permalink
Merge branch 'bugfix/7994_coverity_errors' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Refs #7994
  • Loading branch information
martyngigg committed Oct 4, 2013
2 parents 175b8d1 + 6f9c034 commit 5caef6e
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 85 deletions.
8 changes: 5 additions & 3 deletions Code/Mantid/Framework/API/inc/MantidAPI/FileFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ namespace Mantid
{
public:
std::string getFullPath(const std::string& filename)const;
std::string getPath(const std::vector<IArchiveSearch_sptr>& archs, const std::set<std::string>& filename, const std::vector<std::string>& extensions)const;
std::string getPath(const std::vector<IArchiveSearch_sptr>& archs, const std::set<std::string>& filename,
const std::vector<std::string>& extensions)const;
/// DO NOT USE! MADE PUBLIC FOR TESTING ONLY.
std::string makeFileName(const std::string& hint, const Kernel::InstrumentInfo& instrument)const;
void setCaseSensitive(const bool cs);
bool getCaseSensitive() const;
std::string findRun(const std::string& hintstr,const std::set<std::string> *exts)const;
std::string findRun(const std::string& hintstr,const std::vector<std::string> &exts = std::vector<std::string>())const;
std::string findRun(const std::string& hintstr,const std::set<std::string> & exts)const;
std::string findRun(const std::string& hintstr,
const std::vector<std::string> &exts = std::vector<std::string>())const;
std::vector<std::string> findRuns(const std::string& hintstr)const;
/// DO NOT USE! MADE PUBLIC FOR TESTING ONLY.
const Kernel::InstrumentInfo getInstrument(const std::string& hint) const;
Expand Down
8 changes: 4 additions & 4 deletions Code/Mantid/Framework/API/src/FileFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,15 @@ namespace Mantid
* this argument is ignored.
* @return The full path to the file or empty string if not found
*/
std::string FileFinderImpl::findRun(const std::string& hintstr, const std::set<std::string> *exts) const
std::string FileFinderImpl::findRun(const std::string& hintstr, const std::set<std::string> &exts) const
{
std::string hint = Kernel::Strings::strip(hintstr);
g_log.debug() << "set findRun(\'" << hintstr << "\', exts[" << exts->size() << "])\n";
g_log.debug() << "set findRun(\'" << hintstr << "\', exts[" << exts.size() << "])\n";
if (hint.empty())
return "";
std::vector<std::string> exts_v;
if (exts != NULL && exts->size() > 0)
exts_v.assign(exts->begin(), exts->end());
if (!exts.empty())
exts_v.assign(exts.begin(), exts.end());

return this->findRun(hint, exts_v);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ namespace Mantid
* Index into vector: workspace index in the lhs;
* Value at that index: workspace index of the rhs to apply to the WI in the lhs. -1 if not found.
*/
typedef std::vector< int64_t > BinaryOperationTable;
typedef std::vector< int64_t> BinaryOperationTable;
typedef boost::shared_ptr<BinaryOperationTable> BinaryOperationTable_sptr;

static BinaryOperationTable * buildBinaryOperationTable(API::MatrixWorkspace_const_sptr lhs, API::MatrixWorkspace_const_sptr rhs);
static BinaryOperationTable_sptr
buildBinaryOperationTable(const API::MatrixWorkspace_const_sptr & lhs, const API::MatrixWorkspace_const_sptr & rhs);


//protected:
private:
// Overridden Algorithm methods
void init();
Expand Down
12 changes: 8 additions & 4 deletions Code/Mantid/Framework/Algorithms/src/BinaryOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "MantidKernel/Timer.h"
#include "MantidDataObjects/WorkspaceSingleValue.h"

#include <boost/make_shared.hpp>

using namespace Mantid::Geometry;
using namespace Mantid::API;
using namespace Mantid::Kernel;
Expand Down Expand Up @@ -675,10 +677,11 @@ namespace Mantid
*/
void BinaryOperation::do2D( bool mismatchedSpectra)
{
BinaryOperationTable * table = NULL;
BinaryOperationTable_sptr table;
if (mismatchedSpectra)
{
table = BinaryOperation::buildBinaryOperationTable(m_lhs, m_rhs);

}

// Propagate any masking first or it could mess up the numbers
//TODO: Check if this works for event workspaces...
Expand Down Expand Up @@ -999,12 +1002,13 @@ namespace Mantid
* @return map from detector ID to workspace index for the RHS workspace.
* NULL if there is not a 1:1 mapping from detector ID to workspace index (e.g more than one detector per pixel).
*/
BinaryOperation::BinaryOperationTable * BinaryOperation::buildBinaryOperationTable(MatrixWorkspace_const_sptr lhs, MatrixWorkspace_const_sptr rhs)
BinaryOperation::BinaryOperationTable_sptr
BinaryOperation::buildBinaryOperationTable(const MatrixWorkspace_const_sptr &lhs, const MatrixWorkspace_const_sptr & rhs)
{
//An addition table is a list of pairs:
// First int = workspace index in the EW being added
// Second int = workspace index to which it will be added in the OUTPUT EW. -1 if it should add a new entry at the end.
BinaryOperationTable * table = new BinaryOperationTable();
auto table = boost::make_shared<BinaryOperationTable>();

int rhs_nhist = static_cast<int>(rhs->getNumberHistograms());
int lhs_nhist = static_cast<int>(lhs->getNumberHistograms());
Expand Down
14 changes: 7 additions & 7 deletions Code/Mantid/Framework/Algorithms/test/BinaryOperationTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ class BinaryOperationTest : public CxxTest::TestSuite
}


BinaryOperation::BinaryOperationTable * do_test_buildBinaryOperationTable(std::vector< std::vector<int> > lhs, std::vector< std::vector<int> > rhs,
BinaryOperation::BinaryOperationTable_sptr do_test_buildBinaryOperationTable(std::vector< std::vector<int> > lhs, std::vector< std::vector<int> > rhs,
bool expect_throw = false)
{
EventWorkspace_sptr lhsWS = WorkspaceCreationHelper::CreateGroupedEventWorkspace(lhs, 50, 1.0);
EventWorkspace_sptr rhsWS = WorkspaceCreationHelper::CreateGroupedEventWorkspace(rhs, 50, 1.0);
BinaryOperation::BinaryOperationTable * table = 0;
BinaryOperation::BinaryOperationTable_sptr table;
Mantid::Kernel::Timer timer1;
if (expect_throw)
{
Expand Down Expand Up @@ -206,7 +206,7 @@ class BinaryOperationTest : public CxxTest::TestSuite
// 3 detectors in each on the rhs
rhs[i/3].push_back(i);
}
BinaryOperation::BinaryOperationTable * table = do_test_buildBinaryOperationTable(lhs, rhs);
auto table = do_test_buildBinaryOperationTable(lhs, rhs);
for (int i=0; i<6; i++)
{
TS_ASSERT_EQUALS( (*table)[i], i/3);
Expand All @@ -223,7 +223,7 @@ class BinaryOperationTest : public CxxTest::TestSuite
// 3 detectors in each on the rhs
rhs[i/3].push_back(i);
}
BinaryOperation::BinaryOperationTable * table = do_test_buildBinaryOperationTable(lhs, rhs, false);
auto table = do_test_buildBinaryOperationTable(lhs, rhs, false);
TS_ASSERT_EQUALS( (*table)[0], 1);
TS_ASSERT_EQUALS( (*table)[1], 1);
TS_ASSERT_EQUALS( (*table)[2], 1);
Expand All @@ -243,7 +243,7 @@ class BinaryOperationTest : public CxxTest::TestSuite
// 4 detectors in each on the rhs
rhs[i/4].push_back(i);
}
BinaryOperation::BinaryOperationTable * table = do_test_buildBinaryOperationTable(lhs, rhs);
auto table = do_test_buildBinaryOperationTable(lhs, rhs);
for (int i=0; i<8; i++)
{
TS_ASSERT_EQUALS( (*table)[i], i/2);
Expand All @@ -260,7 +260,7 @@ class BinaryOperationTest : public CxxTest::TestSuite
// 6 detectors in each on the rhs
rhs[i/6].push_back(i);
}
BinaryOperation::BinaryOperationTable * table = do_test_buildBinaryOperationTable(lhs, rhs, false);
auto table = do_test_buildBinaryOperationTable(lhs, rhs, false);
TS_ASSERT_EQUALS( (*table)[0], 0); //0-3 go into 0-5
TS_ASSERT_EQUALS( (*table)[1], -1); //4-7 fails to go anywhere
TS_ASSERT_EQUALS( (*table)[2], 1); //8-11 goes into 6-11
Expand All @@ -277,7 +277,7 @@ class BinaryOperationTest : public CxxTest::TestSuite
// 1000 detectors in each on the rhs
rhs[i/100][i%100] = i;
}
BinaryOperation::BinaryOperationTable * table = do_test_buildBinaryOperationTable(lhs, rhs);
auto table = do_test_buildBinaryOperationTable(lhs, rhs);
for (int i=0; i<2000; i++)
{
TS_ASSERT_EQUALS( (*table)[i], i/100);
Expand Down
5 changes: 3 additions & 2 deletions Code/Mantid/Framework/CurveFitting/src/FitMW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ namespace
const size_t nhistograms = functionsToDisplay.size() + 2;
const size_t nyvalues = ivalues->size();
auto ws = createEmptyResultWS(nhistograms, nyvalues);
API::TextAxis *textAxis = dynamic_cast<API::TextAxis*>(ws->getAxis(1));
// The workspace was constructed with a TextAxis
API::TextAxis *textAxis = static_cast<API::TextAxis*>(ws->getAxis(1));
textAxis->setLabel(0,"Data");
textAxis->setLabel(1,"Calc");
textAxis->setLabel(2,"Diff");
Expand All @@ -314,7 +315,7 @@ namespace
size_t wsIndex(1); // Zero reserved for data
for(auto it = functionsToDisplay.begin(); it != iend; ++it)
{
if(textAxis && wsIndex > 2) textAxis->setLabel(wsIndex, (*it)->name());
if(wsIndex > 2) textAxis->setLabel(wsIndex, (*it)->name());
addFunctionValuesToWS(*it, ws, wsIndex, domain, values);
if(it == functionsToDisplay.begin()) wsIndex += 2; //Skip difference histogram for now
else ++wsIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@ namespace Geometry
{
public:
// Default constructor. a = b = c = 1, alpha = beta = gamma = 90 degrees
OrientedLattice(Kernel::DblMatrix Umatrix=Kernel::DblMatrix(3,3,true));
OrientedLattice(const Kernel::DblMatrix & Umatrix = Kernel::DblMatrix(3,3,true));
//Copy constructor
OrientedLattice(const OrientedLattice& other);
// a,b,c constructor
OrientedLattice(const double _a,const double _b,const double _c,Kernel::DblMatrix Umatrix=Kernel::DblMatrix(3,3,true));
OrientedLattice(const double _a,const double _b,const double _c,
const Kernel::DblMatrix & Umatrix = Kernel::DblMatrix(3,3,true));
//a,b,c,alpha,beta,gamma constructor
OrientedLattice(const double _a,const double _b,const double _c,const double _alpha,const double _beta,const double _gamma,Kernel::DblMatrix Umatrix=Kernel::DblMatrix(3,3,true),const int angleunit=angDegrees);
OrientedLattice(const double _a,const double _b,const double _c,const double _alpha,const double _beta,
const double _gamma, const Kernel::DblMatrix & Umatrix = Kernel::DblMatrix(3,3,true),
const int angleunit=angDegrees);
//UnitCell constructor
OrientedLattice(UnitCell uc ,Kernel::DblMatrix Umatrix=Kernel::DblMatrix(3,3,true));
OrientedLattice(const UnitCell & uc , const Kernel::DblMatrix & Umatrix = Kernel::DblMatrix(3,3,true));
// Destructor
virtual ~OrientedLattice();

Expand Down
15 changes: 10 additions & 5 deletions Code/Mantid/Framework/Geometry/src/Crystal/OrientedLattice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Geometry
/** Default constructor
@param Umatrix :: orientation matrix U. By default this will be identity matrix
*/
OrientedLattice::OrientedLattice(DblMatrix Umatrix):UnitCell()
OrientedLattice::OrientedLattice(const DblMatrix & Umatrix) : UnitCell()
{
if (Umatrix.isRotation()==true)
{
Expand All @@ -23,7 +23,7 @@ namespace Geometry
/** Copy constructor
@param other :: The OrientedLattice from which to copy information
*/
OrientedLattice::OrientedLattice(const OrientedLattice& other):UnitCell(other),U(other.U),UB(other.UB)
OrientedLattice::OrientedLattice(const OrientedLattice& other) : UnitCell(other),U(other.U),UB(other.UB)
{
}

Expand All @@ -33,7 +33,8 @@ namespace Geometry
@param _c :: lattice parameter \f$ c \f$ with \f$\alpha = \beta = \gamma = 90^\circ \f$
@param Umatrix :: orientation matrix U
*/
OrientedLattice::OrientedLattice(const double _a,const double _b,const double _c,DblMatrix Umatrix):UnitCell(_a,_b,_c)
OrientedLattice::OrientedLattice(const double _a,const double _b,const double _c,
const DblMatrix &Umatrix) : UnitCell(_a,_b,_c)
{
if (Umatrix.isRotation()==true)
{
Expand All @@ -53,7 +54,10 @@ namespace Geometry
@param angleunit :: units for angle, of type #AngleUnits. Default is degrees.
@param Umatrix :: orientation matrix U
*/
OrientedLattice::OrientedLattice(const double _a,const double _b,const double _c,const double _alpha,const double _beta,const double _gamma,DblMatrix Umatrix, const int angleunit):UnitCell(_a,_b,_c,_alpha,_beta,_gamma,angleunit)
OrientedLattice::OrientedLattice(const double _a,const double _b,const double _c,const double _alpha,
const double _beta,const double _gamma, const DblMatrix &Umatrix,
const int angleunit)
:UnitCell(_a,_b,_c,_alpha,_beta,_gamma,angleunit)
{
if (Umatrix.isRotation()==true)
{
Expand All @@ -67,7 +71,8 @@ namespace Geometry
@param uc :: UnitCell
@param Umatrix :: orientation matrix U. By default this will be identity matrix
*/
OrientedLattice::OrientedLattice(UnitCell uc,DblMatrix Umatrix):UnitCell(uc),U(Umatrix)
OrientedLattice::OrientedLattice(const UnitCell & uc, const DblMatrix & Umatrix)
: UnitCell(uc),U(Umatrix)
{
if (Umatrix.isRotation()==true)
{
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Kernel/src/RemoteJobManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ std::istream & RemoteJobManager::httpPost(const std::string &path, const PostDat

postBody << finalBoundaryLine;

req.setContentLength( postBody.str().size());
req.setContentLength( static_cast<int>(postBody.str().size()));

std::ostream &postStream = m_session->sendRequest( req);

Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Nexus/inc/MantidNexus/NexusClasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ namespace Mantid
Kernel::Property* createSingleValueProperty();
///Parse a time series
template<class TYPE>
Kernel::Property* parseTimeSeries(const std::string & logName, TYPE times, const std::string& time0 = "")
Kernel::Property* parseTimeSeries(const std::string & logName, const TYPE &times, const std::string& time0 = "")
{
std::string start_time = (!time0.empty()) ? time0 : times.attributes("start");
if (start_time.empty())
Expand Down Expand Up @@ -676,7 +676,7 @@ namespace Mantid
///@param times :: the array of time offsets
///@returns a property pointer
template<class NX_TYPE,class TIME_TYPE>
Kernel::Property* loadValues(const std::string& logName, NX_TYPE value, Kernel::DateAndTime start_t,TIME_TYPE times)
Kernel::Property* loadValues(const std::string& logName, NX_TYPE & value, Kernel::DateAndTime start_t, const TIME_TYPE & times)
{
value.openLocal();
Kernel::TimeSeriesProperty<double>* logv = new Kernel::TimeSeriesProperty<double>(logName);
Expand Down
21 changes: 7 additions & 14 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3387,29 +3387,23 @@ void ApplicationWindow::convertTableToWorkspace()
{
Table* t = dynamic_cast<Table*>(activeWindow(TableWindow));
if (!t) return;
MantidTable* mt = dynamic_cast<MantidTable*>(t);
if (!mt)
{
mt = convertTableToTableWorkspace(t);
}
convertTableToTableWorkspace(t);
}

/**
* Convert Table in the active window to a TableWorkspace
* Convert Table in the active window to a MatrixWorkspace
*/
void ApplicationWindow::convertTableToMatrixWorkspace()
{
Table* t = dynamic_cast<Table*>(activeWindow(TableWindow));
if (!t) return;
MantidTable* mt = dynamic_cast<MantidTable*>(t);
if (!mt)
if(auto *mt = dynamic_cast<MantidTable*>(t))
{
mt = convertTableToTableWorkspace(t);
QMap<QString,QString> params;
params["InputWorkspace"] = QString::fromStdString(mt->getWorkspaceName());
mantidUI->executeAlgorithmDlg("ConvertTableToMatrixWorkspace",params);
}
if ( !mt ) return;
QMap<QString,QString> params;
params["InputWorkspace"] = QString::fromStdString(mt->getWorkspaceName());
mantidUI->executeAlgorithmDlg("ConvertTableToMatrixWorkspace",params);
}

/**
Expand Down Expand Up @@ -3486,8 +3480,7 @@ MantidTable* ApplicationWindow::convertTableToTableWorkspace(Table* t)
{
Mantid::API::AnalysisDataService::Instance().add(wsName,tws);
}
MantidTable* mt = new MantidTable(scriptingEnv(), tws, t->objectName(), this);
return mt;
return new MantidTable(scriptingEnv(), tws, t->objectName(), this);
}

Matrix* ApplicationWindow::tableToMatrix(Table* t)
Expand Down
9 changes: 5 additions & 4 deletions Code/Mantid/MantidPlot/src/Mantid/MantidMDCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ MantidMDCurve::MantidMDCurve(const QString& wsName,Graph* g,bool err,bool distr,
:MantidCurve(wsName, err),
m_wsName(wsName)
{
if(!g)
{
throw std::invalid_argument("MantidMDCurve::MantidMDCurve() - NULL graph pointer not allowed");
}
init(g,distr,style);
}

Expand Down Expand Up @@ -77,10 +81,7 @@ void MantidMDCurve::init(Graph* g, bool distr, Graph::CurveType style)
{
setStyle(QwtPlotCurve::Lines);
}
if (g)
{
g->insertCurve(this,lineWidth);
}
g->insertCurve(this,lineWidth);
connect(g,SIGNAL(axisScaleChanged(int,bool)),this,SLOT(axisScaleChanged(int,bool)));
observePostDelete();
connect( this, SIGNAL(resetData(const QString&)), this, SLOT(dataReset(const QString&)) );
Expand Down
11 changes: 5 additions & 6 deletions Code/Mantid/MantidPlot/src/Mantid/MantidMatrixCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ MantidMatrixCurve::MantidMatrixCurve(const QString&,const QString& wsName,Graph*
m_wsName(wsName),
m_index(index)
{
if(!g)
{
throw std::invalid_argument("MantidMatrixCurve::MantidMatrixCurve - NULL graph pointer not allowed");
}
init(g,distr,style);
}

Expand Down Expand Up @@ -131,12 +135,7 @@ void MantidMatrixCurve::init(Graph* g,bool distr,Graph::CurveType style)
{
setStyle(QwtPlotCurve::Lines);
}


if (g)
{
g->insertCurve(this,lineWidth);
}
g->insertCurve(this,lineWidth);

// Initialise error bar colour to match curve colour
m_errorSettings->m_color = pen().color();
Expand Down
10 changes: 3 additions & 7 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2306,17 +2306,13 @@ MultiLayer* MantidUI::plotBin(const QString& wsName, const QList<int> & binsList
}

Table *t = createTableFromBins(wsName, ws, binsList, errors);
if(!t) return NULL;
t->confirmClose(false);
t->setAttribute(Qt::WA_QuitOnClose);
MultiLayer* ml(NULL);
if( !t )
{
QApplication::restoreOverrideCursor();
return ml;
}

// TODO: Use the default style instead of a line if nothing is passed into this method
ml = appWindow()->multilayerPlot(t,t->colNames(),style);
MultiLayer *ml = appWindow()->multilayerPlot(t,t->colNames(),style);
if(!ml) return NULL;
m->setBinGraph(ml,t);
ml->confirmClose(false);
QApplication::restoreOverrideCursor();
Expand Down

0 comments on commit 5caef6e

Please sign in to comment.